本文整理匯總了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$;
}