當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Observable.concat方法代碼示例

本文整理匯總了TypeScript中rxjs.Observable.concat方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Observable.concat方法的具體用法?TypeScript Observable.concat怎麽用?TypeScript Observable.concat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rxjs.Observable的用法示例。


在下文中一共展示了Observable.concat方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: catch

    .switchMap(({self}) => {
      if (!self) {
        return Observable.concat(
          Observable.of({
            type: chapter.load,
            self: {name: '', path: ''},
            name: '',
            children: []
          }),
          Observable.of(save()),
          Observable.of(select(null))
        );
      }

      const {path} = self;

      const treePath = `${path}/.tree`;
      if (fs.existsSync(treePath)) {
        try {
          record = JSON.parse(fs.readFileSync(treePath, 'utf8'));
        } catch(err) {}
      }

      let currentInChildren = false;
      const oldChildren = record.children.map(child => child.name);
      const newChildren = getFiles(path);
      record.children.forEach(({name, path: filePath}, index) => {
        if (!fs.existsSync(filePath)) {
          const i = newChildren.indexOf(name);
          if (i > 0) {
            newChildren.splice(i);
          }
          record.children.splice(index);
          currentInChildren = currentInChildren && (name === record.current);
        }
      });

      newChildren.forEach(name => {
        if (oldChildren.indexOf(name) < 0) {
          record.children.push({name, path: `${path}/${name}.md`});
        }
      });

      if (!currentInChildren) {
        record.current = (record.children[0] || {name: null}).name;
      }

      return Observable.concat(
        Observable.of({
          type: chapter.load,
          self,
          name: record.current,
          children: record.children
        }),
        Observable.of(save()),
        Observable.of(select(record.current))
      );
    });
開發者ID:dtysky,項目名稱:MoeNotes,代碼行數:58,代碼來源:chapter.ts

示例2:

 .switchMap(({name1, name2}) => {
   return Observable.concat(
     Observable.of({
       type: chapter.swap,
       child1: {name: name1},
       child2: {name: name2}
     }),
     Observable.of(save())
   );
 });
開發者ID:dtysky,項目名稱:MoeNotes,代碼行數:10,代碼來源:chapter.ts

示例3: createAsyncAction

export function createAsyncAction(fn: Function, type: string, args?: Array<any>, id?: string) {
  let result: Observable<any>;
  let startAction: IAction = createAction(`${type}_START`, args, id);

  try {
    result = Observable.concat(
      ensureObservable(fn.apply(this, args)).startWith(startAction),
      Observable.of(createAction(`${type}_COMPLETE`, undefined, id))
    );
  } catch (e) {
    result = Observable.of(
      startAction,
      createAction(`${type}_ERROR`, e, id)
    );
  }

  return result.map(data => {
    if (data && data.type) {
      return data;
    }

    return createAction(`${type}_SUCCESS`, data, id);
  });
}
開發者ID:DcsMarcRemolt,項目名稱:dcs-store,代碼行數:24,代碼來源:utils.ts


注:本文中的rxjs.Observable.concat方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。