本文整理汇总了TypeScript中rxjs/operators.take函数的典型用法代码示例。如果您正苦于以下问题:TypeScript take函数的具体用法?TypeScript take怎么用?TypeScript take使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了take函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('file replacements work with forked type checker on watch mode', async () => {
host.writeMultipleFiles({
'src/file-replaced.ts': 'export var obj = { one: 1, two: 2 };',
'src/file.ts': `export var obj = { one: 1 };`,
'src/main.ts': `
import { obj } from './file';
console.log(obj.two);
`,
});
const overrides = {
fileReplacements: [{
replace: normalize('/src/file.ts'),
with: normalize('/src/file-replaced.ts'),
}],
watch: true,
};
const unexpectedError = `Property 'two' does not exist on type '{ one: number; }'`;
const expectedError = `Property 'prop' does not exist on type '{}'`;
const logger = new TestLogger('rebuild-type-errors');
// Race between a timeout and the expected log entry.
const stop$ = race<null | string>(
of(null).pipe(delay(45000 * 2 / 3)),
logger.pipe(
filter(entry => entry.message.includes(expectedError)),
map(entry => entry.message),
take(1),
),
);
let errorAdded = false;
const run = await architect.scheduleTarget(target, overrides, { logger });
run.output.pipe(
tap((buildEvent) => expect(buildEvent.success).toBe(true, 'build should succeed')),
tap(() => {
// Introduce a known type error to detect in the logger filter.
if (!errorAdded) {
host.appendToFile('src/main.ts', 'console.log({}.prop);');
errorAdded = true;
}
}),
takeUntil(stop$),
).subscribe();
const res = await stop$.toPromise();
expect(res).not.toBe(null, 'Test timed out.');
expect(res).not.toContain(unexpectedError);
await run.stop();
});
示例2: it
it ('Minimal (implied defaults)', () => {
const newSetting: UserSettingState = UserSettingUtil.updateUserSettingState(userSettingState, mutable => {
mutable.boardCode = 'TEST&=123';
});
userSettingSubject.next(newSetting);
urlObservable
.pipe(
take(1)
)
.subscribe(s => {
const parsedState = userSettingStateFromQueryString(s);
expect(parsedState).toEqual(newSetting);
})
});
示例3: resolve
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Hero> {
let id = +route.paramMap.get('id')
return this.heroService.getHero(id).pipe(
take(1),
map(hero => {
if (hero) {
return hero;
} else {
this.router.navigate(['heroes']);
return null;
}
})
)
}
示例4: it
it('should update streaming translations on language change', (done: Function) => {
translations = {"TEST": "This is a test"};
translate.use('en');
translate.stream('TEST').pipe(take(3), toArray()).subscribe((res: string[]) => {
const expected = ['This is a test', 'Dit is een test', 'This is a test'];
expect(res).toEqual(expected);
done();
});
translate.setTranslation('nl', {"TEST": "Dit is een test"});
translate.use('nl');
translate.use('en');
});
示例5: it
it(`handles function selection on a base path that doesn't exist yet`, () => {
const nonExistentSubStore = ngRedux.configureSubStore(
['sure', 'whatever'],
(state: any, action: any) => ({ ...state, value: action.newValue })
);
nonExistentSubStore
.select(s => (s ? s.value : s))
.pipe(take(2), toArray())
.subscribe(v => expect(v).toEqual([undefined, 'now I exist']));
nonExistentSubStore.dispatch<AnyAction>({
type: 'nvm',
newValue: 'now I exist',
});
});
示例6: test
test('Receive correct message type', t => {
const service = new MqttService(t.context.mqtt);
const observer = service.observe('/test/hallo2').pipe(take(1));
observer.subscribe(value => {
t.is(value.topic, 'test/hallo2');
t.is(value.val, 'world');
t.is(value.retain, false);
});
t.context.mqtt.publish('test/hallo2', 'world', { retain: false, qos: 0 });
return observer;
});
示例7: mergeMap
mergeMap((aObject: Ha4usObject) => {
return this.$states.observe(aObject.topic).pipe(
timeoutWith(100, of({})),
take(1),
map((state: Ha4usMessage) => {
delete state.topic
delete state.match
return {
object: aObject,
state: state,
}
})
)
}),
示例8: resolve
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Prestation> {
const id = route.paramMap.get('id');
return this.prestationService.getPrestation(id).pipe(
take(1),
tap((data) => {
if (data) {
return data;
} else {
this.router.navigate(['prestations/chart']);
return null;
}
})
);
}
示例9: getFilters
/**
* Get Filters
*
* @returns {Observable<any>}
*/
getFilters(): any
{
return this._store.pipe(
select(getFiltersLoaded),
tap(loaded => {
if ( !loaded )
{
this._store.dispatch(new fromStore.GetFilters([]));
}
}),
filter(loaded => loaded),
take(1)
);
}
示例10: onSubmit
onSubmit() {
const fullPath = `${this.rootFolder}/${this.form.get("folderName").value}`;
this.dataGateway.createLocalFolder(fullPath).pipe(
take(1)
).subscribeTracked(this, () => {
this.localFileRepository.reloadPath(this.rootFolder);
this.modal.close();
}, err => {
this.form.setErrors({
creationFailure: err.message
})
});
}