本文整理汇总了TypeScript中rxjs/operators.startWith函数的典型用法代码示例。如果您正苦于以下问题:TypeScript startWith函数的具体用法?TypeScript startWith怎么用?TypeScript startWith使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了startWith函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: initialize
public initialize() {
return {
view: {
base: this.intent.test().pipe(
scan((acc, next: any) => acc + 1, 1),
share(),
startWith(1),
),
test: this.intent.test().pipe(
scan((acc, next: any) => acc + 1, 1),
share(),
startWith(1),
),
test2: this.subject.pipe(
map(({ type, payload, states }) => {
switch (type) {
case 'subject-test':
return payload + states.test2;
default:
return payload;
}
}),
startWith(1),
),
},
};
}
示例2: it
it('should convert observable obeject to ordinal object', done => {
const aValue = new Subject();
const bValue = new Subject();
const BUFFER_COUNT = 4;
const values = createObject(
aValue.pipe(startWith('')),
bValue.pipe(startWith('')),
);
subscription.add(
combineTemplate(values)
.pipe(bufferCount(BUFFER_COUNT))
.subscribe(v => {
/*tslint:disable:no-magic-numbers*/
expect(v[0]).to.be.deep.eq(createObject('', ''));
expect(v[1]).to.be.deep.eq(createObject('200', ''));
expect(v[2]).to.be.deep.eq(createObject('200', '300'));
expect(v[3]).to.be.deep.eq(createObject('OK', '300'));
/*tslint:enable:no-magic-numbers*/
done();
}),
);
aValue.next('200');
bValue.next('300');
aValue.next('OK');
});
示例3: getRecentApps
/**
* Creates an observable list of recently opened apps
* @param {number} max
* @returns {Observable<any[]>}
*/
getRecentApps(max = 20): Observable<RecentAppTab[]> {
return combineLatest(
this.localRepository.getRecentApps().pipe(
startWith([])
),
this.platformRepository.getRecentApps().pipe(
map(apps => apps || []),
startWith([])
), (localApps, platformApps) => [...localApps, ...platformApps].sort((a, b) => b.time - a.time).slice(0, max)
);
}
示例4: sampleObservable
export function sampleObservable(obs: Observable<any>, scheduler?: any) {
return obs.pipe(
sampleTime(100, scheduler),
share(),
startWith('')
);
}
示例5: isErrorLike
cascade =>
isErrorLike(cascade.final)
? [cascade.final]
: queryConfiguredExtensions({ queryGraphQL }, cascade).pipe(
catchError(error => [asError(error) as ErrorLike]),
startWith(LOADING)
)
示例6: app
return Object.keys(apps).reduce((states, key) => {
const app = apps[key];
const nextState = app(subject, initialState[key]);
if (nextState.view) {
if (!isObservable(nextState.view)) {
throw new Error(`Application view of ${key} must be Observable.`);
}
nextState.view = nextState.view.pipe(startWith(initialState[key]));
if (!states.view) {
states.view = {};
}
if (!isDefined(states.view[key])) {
states.view[key] = nextState.view;
} else {
states.view[key] = merge(states.view[key], nextState.view);
}
}
for (const key in nextState) {
if (key !== 'view') {
if (!nextState[key] || !(nextState[key] instanceof Observable)) {
throw new Error(`Property ${key} must be Observable.`);
}
if (states[key]) {
states[key] = merge(states[key], nextState[key]);
} else {
states[key] = nextState[key];
}
}
}
return states;
}, states);
示例7: addLoadingCount
function addLoadingCount(count$: Observable<number>) {
count$
.pipe(
distinctUntilChanged(),
tap(count => {
if (count < 0) {
throw new Error(
'Observables passed to loadingCount.add() must only emit positive numbers'
);
}
}),
// use takeUntil() so that we can finish each stream on stop() the same way we do when they complete,
// by removing the previous count from the total
takeUntil(stop$),
endWith(0),
startWith(0),
pairwise(),
map(([prev, next]) => next - prev)
)
.subscribe({
next: delta => {
loadingCount$.next(loadingCount$.getValue() + delta);
},
error: error => {
if (fatalErrors) {
fatalErrors.add(error);
}
},
});
}
示例8: ngOnInit
ngOnInit () {
this.playlist$ = this._route.paramMap.pipe(
map(paramMap => ({ playlistId: paramMap.get('id'), playlistOwnerId: paramMap.get('user') })),
switchMap(params =>
this._spotifyService.getPlaylist(params.playlistOwnerId, params.playlistId)
),
map(playlist => ({
isLoading: false,
result: playlist
})),
startWith({
isLoading: true,
result: null
}),
shareReplay()
);
this.tracks$ = this.playlist$.pipe(
filter(o => !o.isLoading && !!o.result),
map(o => o.result.Tracks)
);
this.playlistUrl$ = this.playlist$.pipe(
filter(o => !o.isLoading && !!o.result),
map(o => o.result),
map(playlist => playlist.ImageUrls.length ? playlist.ImageUrls[0] : '')
);
}
示例9: canExecuteFromNgForm
export function canExecuteFromNgForm(form: AbstractControl | AbstractControlDirective): Observable<boolean> {
return form.statusChanges!.pipe(
startWith(form.valid),
map(() => !!form.valid),
distinctUntilChanged(),
);
}
示例10: app
function app(sources: any): any {
return {
other: sources.other.pipe(
take(1),
startWith('a')
),
};
}