當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript operators.share函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。