本文整理汇总了TypeScript中rxjs/operators.share函数的典型用法代码示例。如果您正苦于以下问题:TypeScript share函数的具体用法?TypeScript share怎么用?TypeScript share使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了share函数的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),
),
},
};
}
开发者ID:brn,项目名称:react-mvi,代码行数:27,代码来源:factory.spec.ts
示例2: constructor
constructor() {
this.everySecond$ = timer(1000, 1000).pipe(
share(),
);
this.everyHalfSecond$ = timer(500, 500).pipe(
share(),
);
}
开发者ID:m-sc,项目名称:yamcs,代码行数:8,代码来源:Synchronizer.ts
示例3: share1
share1() {
// emit value in 1s
const source = timer(1000);
// log side effect, emit result
const example = source.pipe(
tap(() => console.log('***SIDE EFFECT***')),
mapTo('***RESULT***')
);
/*
***NOT SHARED, SIDE EFFECT WILL BE EXECUTED TWICE***
output:
"***SIDE EFFECT***"
"***RESULT***"
"***SIDE EFFECT***"
"***RESULT***"
*/
const subscribe = example.subscribe(val => console.log(val));
const subscribeTwo = example.subscribe(val => console.log(val));
// share observable among subscribers
const sharedExample = example.pipe(share());
/*
***SHARED, SIDE EFFECT EXECUTED ONCE***
output:
"***SIDE EFFECT***"
"***RESULT***"
"***RESULT***"
*/
const subscribeThree = sharedExample.subscribe(val => console.log(val));
const subscribeFour = sharedExample.subscribe(val => console.log(val));
}
开发者ID:zwvista,项目名称:SampleMisc,代码行数:32,代码来源:connectable.service.ts
示例4: ngOnInit
ngOnInit() {
this.movieCollection = this.userService.getMovieCollection();
this.movies$ = this.movieCollection.valueChanges().pipe(
map(Movie.fromFirebaseCollection),
share()
);
}
开发者ID:dArignac,项目名称:treasury,代码行数:7,代码来源:movie-list.component.ts
示例5: sampleObservable
export function sampleObservable(obs: Observable<any>, scheduler?: any) {
return obs.pipe(
sampleTime(100, scheduler),
share(),
startWith('')
);
}
开发者ID:tjoskar,项目名称:ng2-lazyload-image,代码行数:7,代码来源:scroll-listener.ts
示例6: refresh
refresh() {
this.params$ = this.sharedAboutService.getFeatureInfo()
.pipe(map((featureInfo: FeatureInfo) => ({
schedulesEnabled: featureInfo.schedulesEnabled
})));
this.counters$ = this.sharedAboutService.getFeatureInfo()
.pipe(mergeMap(
(featureInfo: FeatureInfo) => {
const arr = [];
arr.push(this.tasksService.getDefinitions({ q: '', size: 1, page: 0, sort: null, order: null }),
this.tasksService.getExecutions({ q: '', size: 1, page: 0, sort: null, order: null }));
if (featureInfo.schedulesEnabled) {
arr.push(this.tasksService.getSchedules({ q: '', size: 1, page: 0, sort: null, order: null }));
}
return forkJoin([...arr])
.pipe(map((counters) => {
const result = {
schedulesEnabled: featureInfo.schedulesEnabled,
definitions: (counters[0] as Page<TaskDefinition>).totalElements,
executions: (counters[1] as Page<TaskExecution>).totalElements
};
if (result.schedulesEnabled) {
result['schedules'] = (counters[2] as Page<TaskSchedule>).totalElements;
}
return result;
}));
}
))
.pipe(share());
}
开发者ID:BoykoAlex,项目名称:spring-cloud-dataflow-ui,代码行数:30,代码来源:tasks-tabulation.component.ts
示例7: return
return (input$: Observable<boolean>) => {
let pending = null;
const filteredInput$ = input$.pipe(
map(open => ({open})), filter(event => {
const currentlyOpen = isOpenedFn();
if (currentlyOpen !== event.open && (!pending || pending.open === currentlyOpen)) {
pending = event;
return true;
}
if (pending && pending.open !== event.open) {
pending = null;
}
return false;
}),
share());
const delayedOpen$ = filteredInput$.pipe(filter(event => event.open), delayOrNoop(openDelay));
const delayedClose$ = filteredInput$.pipe(filter(event => !event.open), delayOrNoop(closeDelay));
return merge(delayedOpen$, delayedClose$)
.pipe(
filter(event => {
if (event === pending) {
pending = null;
return event.open !== isOpenedFn();
}
return false;
}),
map(event => event.open));
};
开发者ID:maxokorokov,项目名称:core,代码行数:28,代码来源:triggers.ts
示例8: it
it("should call unsubscribe on unsubscription if the Observable implementation has an unsubscribe function", () => {
/* tslint:enable:max-line-length */
let disposeHasBeenCalled = 0;
const myObs = {
subscribe(_a : () => void, _b : () => void, _c : () => {}) {
return {
unsubscribe() {
disposeHasBeenCalled++;
},
};
},
};
const rxObs = castToObservable(myObs);
const sub1 = rxObs.subscribe();
const sub2 = rxObs.subscribe();
sub1.unsubscribe();
sub2.unsubscribe();
expect(disposeHasBeenCalled).toBe(2);
// reset counter
disposeHasBeenCalled = 0;
const sharedRxObs = rxObs.pipe(share());
const sharedSub1 = sharedRxObs.subscribe();
const sharedSub2 = sharedRxObs.subscribe();
sharedSub1.unsubscribe();
sharedSub2.unsubscribe();
expect(disposeHasBeenCalled).toBe(1);
});
开发者ID:canalplus,项目名称:rx-player,代码行数:30,代码来源:cast_to_observable.test.ts
示例9: unsubscribe
export function fromRef<T>(ref: DatabaseQuery, event: ListenEvent, listenType = 'on'): Observable<AngularFireAction<DatabaseSnapshot<T>>> {
return new Observable<SnapshotPrevKey<T>>(subscriber => {
const fn = ref[listenType](event, (snapshot, prevKey) => {
subscriber.next({ snapshot, prevKey });
if (listenType == 'once') { subscriber.complete(); }
}, subscriber.error.bind(subscriber));
if (listenType == 'on') {
return { unsubscribe() { ref.off(event, fn)} };
} else {
return { unsubscribe() { } };
}
}).pipe(
map(payload => {
const { snapshot, prevKey } = payload;
let key: string | null = null;
if (snapshot.exists()) { key = snapshot.key; }
return { type: event, payload: snapshot, prevKey, key };
}),
// Ensures subscribe on observable is async. This handles
// a quirk in the SDK where on/once callbacks can happen
// synchronously.
delay(0),
share()
);
}
开发者ID:Tetsumote,项目名称:angularfire2,代码行数:25,代码来源:fromRef.ts
示例10: bindMessageHandlers
public bindMessageHandlers(
client: any,
handlers: MessageMappingProperties[],
transform: (data: any) => Observable<any>,
) {
const disconnect$ = fromEvent(client, DISCONNECT_EVENT).pipe(
share(),
first(),
);
handlers.forEach(({ message, callback }) => {
const source$ = fromEvent(client, message).pipe(
mergeMap((payload: any) => {
const { data, ack } = this.mapPayload(payload);
return transform(callback(data)).pipe(
filter(response => !isNil(response)),
map(response => [response, ack]),
);
}),
takeUntil(disconnect$),
);
source$.subscribe(([response, ack]) => {
if (response.event) {
return client.emit(response.event, response.data);
}
isFunction(ack) && ack(response);
});
});
}
开发者ID:SARAVANA1501,项目名称:nest,代码行数:29,代码来源:io-adapter.ts
注:本文中的rxjs/operators.share函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论