当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript observeOn.observeOn类代码示例

本文整理汇总了TypeScript中rxjs/operator/observeOn.observeOn的典型用法代码示例。如果您正苦于以下问题:TypeScript observeOn类的具体用法?TypeScript observeOn怎么用?TypeScript observeOn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了observeOn类的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类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。