当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript mobx-state-tree.flow函数代码示例

本文整理汇总了TypeScript中mobx-state-tree.flow函数的典型用法代码示例。如果您正苦于以下问题:TypeScript flow函数的具体用法?TypeScript flow怎么用?TypeScript flow使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了flow函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: flow

  .actions(self => ({
    loadTeams: flow(function* load() {
      const backendSrv = getEnv(self).backendSrv;
      const rsp = yield backendSrv.get('/api/teams/search/', { perpage: 50, page: 1 });
      self.map.clear();

      for (let team of rsp.teams) {
        self.map.set(team.id.toString(), Team.create(team));
      }
    }),

    setSearchQuery(query: string) {
      self.search = query;
    },

    loadById: flow(function* load(id: string) {
      if (self.map.has(id)) {
        return;
      }

      const backendSrv = getEnv(self).backendSrv;
      const team = yield backendSrv.get(`/api/teams/${id}`);
      self.map.set(id, Team.create(team));
    }),
  }));
开发者ID:cboggs,项目名称:grafana,代码行数:25,代码来源:TeamsStore.ts

示例2: addMiddleware

 .actions(self => {
     addMiddleware(self, atomic)
     return {
         inc(x) {
             self.z += x
             return self.z
         },
         throwingFn(x) {
             self.z += x
             throw "Oops"
         },
         incProcess: flow(function*(x) {
             yield delay(2)
             self.z += x
             yield delay(2)
             self.z += x
             return self.z
         }),
         throwingProcess: flow(function*(x) {
             yield delay(2)
             self.z += x
             yield delay(2)
             self.z += x
             throw "Oops"
         })
     }
 })
开发者ID:lelandyolo,项目名称:mobx-state-tree,代码行数:27,代码来源:atomic.ts

示例3: return

.actions(self => ({
  addPartialMovie: (obj: any) => {
    return (self as any).addMovie(obj, true);
  },
  addMovie: (obj: any, isPartial: boolean) => {
    if (self.movies.has(obj.id)) {
      const movie = self.movies.get(obj.id);
      return movie!.update(obj, isPartial);
    }

    return self.movies.put(
      Movie.create(mapMovie(obj, isPartial)),
    );
  },
  loadMovieById: flow(function* loadMovieById(movieId: string) {
    const start = new Date();
    const end = addDays(start, 5);
    const result = yield client.query({
      query: fetchMovieByIdQuery,
      fetchPolicy: 'network-only',
      variables: {
        movieId,
        start: start.toISOString().substr(0, 10),
        end: end.toISOString().substr(0, 10),
      },
    });

    (self as any).addMovie(result.data.Movie, false);
  }),
  loadNewMovies: flow(function* loadNewMovies() {
    const query = (fetchPolicy: FetchPolicy = 'network-only') => client.query({
      fetchPolicy,
      query: fetchNewMoviesQuery,
      variables: {
        from: new Date().toISOString().substr(0, 10),
      },
    });

    let result = yield query();
    const isNetworkError = result.error && result.error.message.includes('Network error');

    if (isNetworkError) {
      result = yield query('cache-only');
    }

    self.isOffline = isNetworkError;
    self.isCache = isNetworkError && result.data;

    if (!result.data) {
      return;
    }

    result.data.allMovies.map(Movies.addPartialMovie);
    self.comingSoon.clear();
    self.comingSoon.push(
      ...result.data.allMovies.map((movie: { id: string }) => movie.id),
    );
  }),
}))
开发者ID:birkir,项目名称:kvikmyndr-app,代码行数:59,代码来源:movies.ts

示例4: flow

.actions(self => ({
  loadWeek: flow(function* loadWeek() {

    self.loading = true;

    const start = new Date();
    const end = addDays(start, 5);

    const query = (fetchPolicy: FetchPolicy = 'network-only') => new Promise((resolve) => {
      client.query({
        fetchPolicy,
        query: fetchMoviesForWeekQuery,
        variables: {
          start: start.toISOString().substr(0, 10),
          end: end.toISOString().substr(0, 10),
        },
      })
      .then(resolve);
      if (fetchPolicy === 'network-only') {
        setTimeout(() => resolve({ error: { message: 'Network error' } }), 5000);
      }
    });

    let result = yield query();
    const isNetworkError = result.error && result.error.message.includes('Network error');

    if (isNetworkError) {
      result = yield query('cache-only');
    }

    self.isOffline = isNetworkError;
    self.isCache = isNetworkError && result.data;

    if (!result.data) {
      return;
    }
    result.data.allMovies.map(Movies.addPartialMovie);

    result.data.allMovies.forEach((movie: IMovieFromDb) => {
      movie.showtimes.forEach((showtime) => {
        const dateKey = addHours(showtime.playingAt, -4).toISOString().substr(0, 10);

        if (!self.dates.has(dateKey)) {
          self.dates.put({
            date: dateKey,
            movies: {},
          });
        }

        const dateOf = self.dates.get(dateKey);
        if (dateOf) {
          dateOf.movies.put({ id: movie.id, movie: movie.id });
        }
      });
    });

    self.loaded = true;
    self.loading = false;
  }),
}))
开发者ID:birkir,项目名称:kvikmyndr-app,代码行数:60,代码来源:in-theaters.ts

示例5: update

 .actions(self => ({
   update() {
     return flow(function* () {
       self.updateMetadata = yield CodePush.getUpdateMetadata();
     })();
   },
 }))
开发者ID:birkir,项目名称:kvikmyndr-app,代码行数:7,代码来源:update.ts

示例6: flow

  .actions(self => ({
    loadRules: flow(function* load(filters) {
      const backendSrv = getEnv(self).backendSrv;
      self.stateFilter = filters.state; // store state filter used in api query
      const apiRules = yield backendSrv.get('/api/alerts', filters);
      self.rules.clear();

      for (let rule of apiRules) {
        setStateFields(rule, rule.state);

        if (rule.state !== 'paused') {
          if (rule.executionError) {
            rule.info = 'Execution Error: ' + rule.executionError;
          }
          if (rule.evalData && rule.evalData.noData) {
            rule.info = 'Query returned no data';
          }
        }

        self.rules.push(AlertRule.create(rule));
      }
    }),
    setSearchQuery(query: string) {
      self.search = query;
    },
  }));
开发者ID:GPegel,项目名称:grafana,代码行数:26,代码来源:AlertListStore.ts

示例7: flow

 .actions(self => ({
     setTitle: flow(function* setTitle(newTitle) {
         self.helper() // should not be logged
         yield self.helper2() // should be logged
         self.title = newTitle
         return
     })
 }))
开发者ID:lelandyolo,项目名称:mobx-state-tree,代码行数:8,代码来源:action-logger.ts

示例8: flow

  .actions(self => ({
    load: flow(function* load(uid: string) {
      // clear folder state
      if (self.folder && self.folder.uid !== uid) {
        self.folder = null;
      }

      const backendSrv = getEnv(self).backendSrv;
      const res = yield backendSrv.getFolderByUid(uid);
      self.folder = Folder.create({
        id: res.id,
        uid: res.uid,
        title: res.title,
        url: res.url,
        canSave: res.canSave,
        hasChanged: false,
        version: res.version,
      });

      return res;
    }),

    setTitle: function(originalTitle: string, title: string) {
      self.folder.title = title;
      self.folder.hasChanged = originalTitle.toLowerCase() !== title.trim().toLowerCase() && title.trim().length > 0;
    },

    saveFolder: flow(function* saveFolder(options: any) {
      const backendSrv = getEnv(self).backendSrv;
      self.folder.title = self.folder.title.trim();

      const res = yield backendSrv.updateFolder(self.folder, options);
      self.folder.url = res.url;
      self.folder.version = res.version;

      return `${self.folder.url}/settings`;
    }),

    deleteFolder: flow(function* deleteFolder() {
      const backendSrv = getEnv(self).backendSrv;

      return backendSrv.deleteFolder(self.folder.uid);
    }),
  }));
开发者ID:InvariantIO,项目名称:grafana,代码行数:44,代码来源:FolderStore.ts

示例9: flow

  .actions(self => {
    const fetchItems = flow(function*() {
      const items: Array<typeof Item.Type> = yield api.getItems()

      items.forEach(item => self._cache.set(item.id.toString(), item))
    })

    return {
      fetchItems
    }
  })
开发者ID:chaucerbao,项目名称:react-project-template,代码行数:11,代码来源:items.ts

示例10: flow

.actions((self) => {

  const addCinema = (obj: any) => {
    const cinema = { ...obj };
    if (self.cinemas.has(cinema.id)) {
      return;
    }

    return self.cinemas.put(
      Cinema.create(cinema),
    );
  };

  const loadAllCinemas = flow(function* () {

    const result = yield client.query({
      query: fetchAllCinemas,
      fetchPolicy: 'network-only',
    });

    result.data.allCinemas.map(addCinema);
  });

  const loadCinemaById = flow(function* (cinemaId: string) {
    const result = yield client.query({
      query: fetchCinemaByIdQuery,
      fetchPolicy: 'network-only',
      variables: {
        cinemaId,
      },
    });

    addCinema(result.data.Cinema);
  });

  return {
    loadAllCinemas,
    loadCinemaById,
    addCinema,
  };
})
开发者ID:birkir,项目名称:kvikmyndr-app,代码行数:41,代码来源:cinemas.ts


注:本文中的mobx-state-tree.flow函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。