本文整理汇总了TypeScript中rxjs/operators.mapTo函数的典型用法代码示例。如果您正苦于以下问题:TypeScript mapTo函数的具体用法?TypeScript mapTo怎么用?TypeScript mapTo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mapTo函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should raises error when promise rejects', (done: MochaDone) => {
const e1 = concat(
of(1),
timer(10).pipe(mapTo(2)),
timer(10).pipe(mapTo(3)),
timer(100).pipe(mapTo(4))
);
const expected = [1, 2];
const error = new Error('error');
e1.pipe(
debounce((x: number) => {
if (x === 3) {
return new Promise((resolve: any, reject: any) => { reject(error); });
} else {
return new Promise((resolve: any) => { resolve(42); });
}
})
).subscribe((x: number) => {
expect(x).to.equal(expected.shift()); },
(err: any) => {
expect(err).to.be.an('error', 'error');
expect(expected.length).to.equal(0);
done();
}, () => {
done(new Error('should not be called'));
});
});
开发者ID:DallanQ,项目名称:rxjs,代码行数:28,代码来源:debounce-spec.ts
示例2: sample3
sample3() {
const listener = merge(
fromEvent(document, 'mousedown').pipe(mapTo(false)),
fromEvent(document, 'mousemove').pipe(mapTo(true))
)
.pipe(sample(fromEvent(document, 'mouseup')))
.subscribe(isDragging => {
console.log('Were you dragging?', isDragging);
});
}
开发者ID:zwvista,项目名称:SampleMisc,代码行数:10,代码来源:filtering.service.ts
示例3: it
it('should map twice', () => {
const a = hot('-0----1-^-2---3--4-5--6--7-8-|');
const asubs = '^ !';
const expected = '--h---h--h-h--h--h-h-|';
const r = a.pipe(
mapTo(-1),
mapTo('h')
);
expectObservable(r).toBe(expected);
expectSubscriptions(a.subscriptions).toBe(asubs);
});
开发者ID:DallanQ,项目名称:rxjs,代码行数:13,代码来源:mapTo-spec.ts
示例4: ngOnInit
ngOnInit() {
this.time$ = this.store.select("tickReducer");
this.hourBackward$ = new Subject();
this.hourForward$ = new Subject();
this.dayBackward$ = new Subject();
this.dayForward$ = new Subject();
this.merged$ = merge(
this.hourBackward$.pipe(mapTo({type: HOUR_TICK, payload: -1})),
this.hourForward$.pipe(mapTo({type: HOUR_TICK, payload: 1})),
this.dayBackward$.pipe(mapTo({type: DAY_TICK, payload: -1})),
this.dayForward$.pipe(mapTo({type: DAY_TICK, payload: 1})),
interval(1000).pipe(mapTo({type: SECOND_TICK, payload: 1}))
);
}
开发者ID:screenm0nkey,项目名称:angular2-examples-webpack,代码行数:14,代码来源:ngrx-clock-one.component.ts
示例5: constructor
constructor(private socket$: Socket) {
const disconnect$ = this.socket$.fromEvent("disconnect");
const connect$ = this.socket$.fromEvent("connect");
this.connected$ = merge(connect$.pipe(mapTo(true)), disconnect$.pipe(mapTo(false)));
this.message$ = this.socket$
.fromEvent("msg")
.pipe(map((data: SocketMessage) => data.msg));
this.messages$ = this.message$
.pipe(startWith([]))
.pipe(scan((acc: string[], curr: string) => {
return [...acc, curr];
}));
}
开发者ID:screenm0nkey,项目名称:angular2-examples-webpack,代码行数:15,代码来源:chat.service.ts
示例6: switchMap
switchMap(ok => {
if (!ok) {
return [false]
}
return mutateGraphQL(
gql`
mutation DeleteRegistryExtension($extension: ID!) {
extensionRegistry {
deleteExtension(extension: $extension) {
alwaysNil
}
}
}
`,
{ extension }
).pipe(
map(({ data, errors }) => {
if (
!data ||
!data.extensionRegistry ||
!data.extensionRegistry.deleteExtension ||
(errors && errors.length > 0)
) {
throw createAggregateError(errors)
}
}),
mapTo(true)
)
})
开发者ID:JoYiRis,项目名称:sourcegraph,代码行数:29,代码来源:backend.ts
示例7: ofType
const epic3: Epic<FluxStandardAction> = action$ =>
action$.pipe(
ofType('THIRD'),
mapTo({
type: 'third'
})
);
开发者ID:redux-observable,项目名称:redux-observable,代码行数:7,代码来源:typings.ts
示例8: multicast1
multicast1() {
// emit every 2 seconds, take 5
const source = interval(2000).pipe(take(5));
const example = source.pipe(
// since we are multicasting below, side effects will be executed once
tap(() => console.log('Side Effect #1')),
mapTo('Result!')
);
// subscribe subject to source upon connect()
const multi = example.pipe(multicast(() => new Subject())) as ConnectableObservable<string>;
/*
subscribers will share source
output:
"Side Effect #1"
"Result!"
"Result!"
...
*/
const subscriberOne = multi.subscribe(val => console.log(val));
const subscriberTwo = multi.subscribe(val => console.log(val));
// subscribe subject to source
multi.connect();
}
开发者ID:zwvista,项目名称:SampleMisc,代码行数:25,代码来源:connectable.service.ts
示例9: addHandler
function addHandler(h: any) {
timer(50, 20, rxTestScheduler).pipe(
mapTo('ev'),
take(2),
concat(NEVER)
).subscribe(h);
}
开发者ID:DallanQ,项目名称:rxjs,代码行数:7,代码来源:fromEventPattern-spec.ts
示例10: canPlay
"loaded"; // loaded without autoplay enabled
/**
* Emit once a "can-play" message as soon as the clock$ anounce that the content
* can begin to be played.
*
* Warn you if the metadata is not yet loaded metadata by emitting a
* "not-loaded-metadata" message first.
* @param {Observable} clock$
* @returns {Observable}
*/
function canPlay(
clock$ : Observable<IInitClockTick>,
mediaElement : HTMLMediaElement
) : Observable<"can-play"|"not-loaded-metadata"> {
const isLoaded$ = clock$.pipe(
filter((tick) => {
const { seeking, stalled, readyState, currentRange } = tick;
return !seeking &&
stalled == null &&
(readyState === 4 || readyState === 3 && currentRange != null) &&
(!shouldValidateMetadata() || mediaElement.duration > 0);
}),
take(1),
mapTo("can-play" as "can-play")
);
if (shouldValidateMetadata() && mediaElement.duration === 0) {
return observableConcat(
observableOf("not-loaded-metadata" as "not-loaded-metadata"),
isLoaded$
);
}
return isLoaded$;
}
开发者ID:canalplus,项目名称:rx-player,代码行数:36,代码来源:initial_seek_and_play.ts
注:本文中的rxjs/operators.mapTo函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论