本文整理汇总了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'));
});
});
示例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);
});
}
示例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);
});
示例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}))
);
}
示例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];
}));
}
示例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)
)
})
示例7: ofType
const epic3: Epic<FluxStandardAction> = action$ =>
action$.pipe(
ofType('THIRD'),
mapTo({
type: 'third'
})
);
示例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();
}
示例9: addHandler
function addHandler(h: any) {
timer(50, 20, rxTestScheduler).pipe(
mapTo('ev'),
take(2),
concat(NEVER)
).subscribe(h);
}
示例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$;
}