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


TypeScript observeOn.call方法代碼示例

本文整理匯總了TypeScript中rxjs/operator/observeOn.observeOn.call方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript observeOn.call方法的具體用法?TypeScript observeOn.call怎麽用?TypeScript observeOn.call使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rxjs/operator/observeOn.observeOn的用法示例。


在下文中一共展示了observeOn.call方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: Observable

function _fromRef<T, R>(ref: Reference<T>): Observable<R> {
  const ref$ = new Observable(subscriber => {
    const unsubscribe = ref.onSnapshot(subscriber);
    return { unsubscribe };
  });
  return observeOn.call(ref$, new ZoneScheduler(Zone.current));
}
開發者ID:nandollo,項目名稱:angularfire2,代碼行數:7,代碼來源:fromRef.ts

示例2: constructor

  constructor(public app: FirebaseApp) {
    this.auth = app.auth();

    const authState$ = new Observable(subscriber => {
      const unsubscribe = this.auth.onAuthStateChanged(subscriber);
      return { unsubscribe };
    });
    this.authState = observeOn.call(authState$, new ZoneScheduler(Zone.current));

    const idToken$ = new Observable<firebase.User|null>(subscriber => {
      const unsubscribe = this.auth.onIdTokenChanged(subscriber);
      return { unsubscribe };
    }).switchMap(user => {
      return user ? Observable.fromPromise(user.getIdToken()) : Observable.of(null)
    });
    this.idToken = observeOn.call(idToken$, new ZoneScheduler(Zone.current));
  }
開發者ID:cartant,項目名稱:angularfire2,代碼行數:17,代碼來源:auth.ts

示例3: FirebaseIdTokenObservable

export function FirebaseIdTokenObservable(app: FirebaseApp): Observable<firebase.User> {
  const idToken = Observable.create((observer: Observer<firebase.User>) => {
    app.auth().onIdTokenChanged(
      (user?: firebase.User) => observer.next(user),
      (error: firebase.auth.Error) => observer.error(error),
      () => observer.complete()
    )
  });
  return observeOn.call(idToken, new utils.ZoneScheduler(Zone.current));
}
開發者ID:mhartington,項目名稱:angularfire2,代碼行數:10,代碼來源:auth.ts

示例4: FirebaseAuthStateObservable

export function FirebaseAuthStateObservable(app: FirebaseApp): Observable<firebase.User> {
  const authState = Observable.create((observer: Observer<firebase.User>) => {
    app.auth().onAuthStateChanged(
      (user: firebase.User) => observer.next(user!),
      (error: firebase.auth.Error) => observer.error(error),
      () => { observer.complete(); return undefined; }
    );
  });
  return observeOn.call(authState, new ZoneScheduler(Zone.current));
}
開發者ID:nandollo,項目名稱:angularfire2,代碼行數:10,代碼來源:auth.ts

示例5: constructor

  constructor(_initialState: T, action$: Dispatcher, reducer$: Reducer) {
    super(_initialState);

    const actionInQueue$ = observeOn.call(action$, queue);
    const actionAndReducer$ = withLatestFrom.call(actionInQueue$, reducer$);
    const state$ = scan.call(actionAndReducer$, (state, [ action, reducer ]) => {
      return reducer(state, action);
    }, _initialState);

    state$.subscribe(value => this.next(value));
  }
開發者ID:9590,項目名稱:store,代碼行數:11,代碼來源:state.ts

示例6: constructor

  constructor(_initialState: T, actionsDispatcher$: Observable<Action>, reducer: ActionReducer<T>) {
    super(_initialState);

    const actionInQueue$ = observeOn.call(actionsDispatcher$, queue);
    const state$ = scan.call(actionInQueue$, (state: T, action: Action) => {
      if (!action) {
        return state;
      }

      return reducer(state, action);
    }, _initialState);

    state$.subscribe((value: T) => this.next(value));
  }
開發者ID:kekeh,項目名稱:ngx-bootstrap,代碼行數:14,代碼來源:state.class.ts

示例7: FirebaseObjectFactory

export function FirebaseObjectFactory (
  ref: DatabaseReference,
  { preserveSnapshot }: FirebaseObjectFactoryOpts = {}): FirebaseObjectObservable<any> {

  const objectObservable = new FirebaseObjectObservable((obs: Observer<any>) => {
    let fn = ref.on('value', (snapshot: firebase.database.DataSnapshot) => {
      obs.next(preserveSnapshot ? snapshot : utils.unwrapMapFn(snapshot))
    }, err => {
      if (err) { obs.error(err); obs.complete(); }
    });

    return () => ref.off('value', fn);
  }, ref);

  // TODO: should be in the subscription zone instead
  return observeOn.call(objectObservable, new utils.ZoneScheduler(Zone.current));
}
開發者ID:mhartington,項目名稱:angularfire2,代碼行數:17,代碼來源:firebase_object_factory.ts

示例8: fromRef

export function fromRef(ref: DatabaseQuery, event: ListenEvent, listenType = 'on'): Observable<AngularFireAction<DatabaseSnapshot | null>> {
  const ref$ = new Observable<SnapshotPrevKey | null | undefined>(subscriber => {
    const fn = ref[listenType](event, (snapshot, prevKey) => {
      subscriber.next({ snapshot, prevKey })
    }, subscriber.error.bind(subscriber));
    return { unsubscribe() { ref.off(event, fn)} }
  })
  .map((payload: SnapshotPrevKey) =>  { 
    const { snapshot, prevKey } = payload;
    let key: string | null = null;
    if(snapshot) { 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); 
  return observeOn.call(ref$, new ZoneScheduler(Zone.current));
}
開發者ID:cartant,項目名稱:angularfire2,代碼行數:19,代碼來源:fromRef.ts

示例9: firebaseListObservable

/**
 * Creates a FirebaseListObservable from a reference or query. Options can be provided as a second
 * parameter. This function understands the nuances of the Firebase SDK event ordering and other
 * quirks. This function takes into account that not all .on() callbacks are guaranteed to be
 * asynchonous. It creates a initial array from a promise of ref.once('value'), and then starts
 * listening to child events. When the initial array is loaded, the observable starts emitting values.
 */
function firebaseListObservable(ref: database.Reference | DatabaseQuery, {preserveSnapshot}: FirebaseListFactoryOpts = {}): FirebaseListObservable<any> {

  const toValue = preserveSnapshot ? (snapshot => snapshot) : utils.unwrapMapFn;
  const toKey = preserveSnapshot ? (value => value.key) : (value => value.$key);

  const listObs = new FirebaseListObservable(ref, (obs: Observer<any>) => {

    // Keep track of callback handles for calling ref.off(event, handle)
    const handles: { event: string, handle: (a: DatabaseSnapshot, b?: string | null | undefined) => any }[] = [];
    let hasLoaded = false;
    let lastLoadedKey: string = null!;
    let array: DatabaseSnapshot[] = [];

    // The list children are always added to, removed from and changed within
    // the array using the child_added/removed/changed events. The value event
    // is only used to determine when the initial load is complete.

    ref.once('value', (snap: any) => {
      if (snap.exists()) {
        snap.forEach((child: any) => {
          lastLoadedKey = child.key;
        });
        if (array.find((child: any) => toKey(child) === lastLoadedKey)) {
          hasLoaded = true;
          obs.next(array);
        }
      } else {
        hasLoaded = true;
        obs.next(array);
      }
    }, err => {
      if (err) { obs.error(err); obs.complete(); }
    });

    const addFn = ref.on('child_added', (child: any, prevKey: string) => {
      array = onChildAdded(array, toValue(child), toKey, prevKey);
      if (hasLoaded) {
        obs.next(array);
      } else if (child.key === lastLoadedKey) {
        hasLoaded = true;
        obs.next(array);
      }
    }, err => {
      if (err) { obs.error(err); obs.complete(); }
    });
    handles.push({ event: 'child_added', handle: addFn });

    let remFn = ref.on('child_removed', (child: any) => {
      array = onChildRemoved(array, toValue(child), toKey);
      if (hasLoaded) {
        obs.next(array);
      }
    }, err => {
      if (err) { obs.error(err); obs.complete(); }
    });
    handles.push({ event: 'child_removed', handle: remFn });

    let chgFn = ref.on('child_changed', (child: any, prevKey: string) => {
      array = onChildChanged(array, toValue(child), toKey, prevKey);
      if (hasLoaded) {
        obs.next(array);
      }
    }, err => {
      if (err) { obs.error(err); obs.complete(); }
    });
    handles.push({ event: 'child_changed', handle: chgFn });

    return () => {
      // Loop through callback handles and dispose of each event with handle
      // The Firebase SDK requires the reference, event name, and callback to
      // properly unsubscribe, otherwise it can affect other subscriptions.
      handles.forEach(item => {
        ref.off(item.event, item.handle);
      });
    };

  });

  // TODO: should be in the subscription zone instead
  return observeOn.call(listObs, new FirebaseZoneScheduler(new NgZone({})));

}
開發者ID:juampi,項目名稱:angularfire2,代碼行數:89,代碼來源:firebase_list_factory.ts


注:本文中的rxjs/operator/observeOn.observeOn.call方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。