本文整理汇总了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))
);
});
示例2:
.switchMap(({name1, name2}) => {
return Observable.concat(
Observable.of({
type: chapter.swap,
child1: {name: name1},
child2: {name: name2}
}),
Observable.of(save())
);
});
示例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);
});
}