示例#1
0
	in(contents): Observable<boolean> {
		const data = JSON.parse(contents);
		// const parsed = JSON.parse(contents);
		var parsed = [];

		// Save present state of Patients into Backup database
		this.store.dispatch(this.backupActions.save());

		// Full restore
		// parsed = data.full;
		parsed = data.updated;

		const __ = (name, action, db, method = 'init') => {
			return Observable.of(null).do(() => {
				db.upsert(parsed[name], (x) => {
					this.store.dispatch(action[method](db.data()));
					db.save();
				});
			});
		}

		const a = __('diary', this.diaryActions, DiaryDB);
		const b = __('messages', this.messagesActions, MessagesDB);
		const c = __('store', this.storeActions, StoreDB);
		const d = __('storeAction', this.storeActions, StoreActionDB, 'init_actions');
		const x = __('sessions', this.sessionsActions, SessionsDB);
		const y = __('payments', this.paymentsActions, PaymentsDB);
		const z = __('patients', this.patientsActions, PatientsDB);

		return Observable.concat(a, b, c, d, x, y, z)
			.map(() => true)
			.delay(1500)
	}
示例#2
0
  constructor(private zone: NgZone) {
    // Extract a typed version of navigator.serviceWorker.
    this.container = navigator['serviceWorker'] as ServiceWorkerContainer;

    // Final Observable that will always give back the current controlling worker,
    // and follow changes over time.
    this.controllingWorker = Observable
      // Combine current and future controllers.
      .concat(
        // Current controlling worker (if any).
        Observable.of(this.container.controller),
        // Future changes of the controlling worker.
        Observable
          // Track changes of the controlling worker via the controllerchange event.
          .fromEvent(this.container, 'controllerchange')
          // Read the new controller when it changes.
          .map(_ => this.container.controller)
      )
      // Cache the latest controller for immediate delivery.
      .cache(1);
    
    // To make one-off calls to the worker, awaitSingleControllingWorker waits for
    // a controlling worker to exist.
    this.awaitSingleControllingWorker = this
      .controllingWorker
      .filter(worker => !!worker)
      .take(1);

    // Setup the push Observable as a broadcast mechanism for push notifications.
    this.push = Observable
      .defer(() => this.send({cmd: 'push'}))
      .share();
  }
示例#3
0
            .mergeMap(({type, payload})=> {
                switch (type) {
                    case SELECT_REDDIT:
                        return Observable.concat(
                            //isFetching true
                            Observable.of({type: LOADING}),

                            //wait 2 seconds
                            Observable.timer(2000),

                            //request posts
                            reddit.fetchPosts(payload)
                                .map((body)=>({
                                    type: RECEIVE_POSTS,
                                    payload: {reddit: payload, data: body.data}
                                })),

                            //isFetching false, change selected item
                            Observable.of({type: SELECTED_REDDIT, payload})
                        );

                    default:
                        return o$;
                }
            });
        it('should emit values from sourceTwo after sourceOne when used as static method', () => {
            const sourceOne = Observable.of(1,2,3);
            const sourceTwo = Observable.of(4,5,6);
            const example = Observable.concat(sourceOne,sourceTwo);
            const values = {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6};
            const expected = '(abcdef|)';

            expectObservable(example).toBe(expected, values);
        });
示例#5
0
 public add(doc: any): Observable<FalcorJsonGraph.PathValue | FalcorJsonGraph.InvalidPath> {
   let obj: any = {
     _id: doc._id
   };
   this.options.fields.forEach((f: string): void => {
     obj[f] = doc[f];
   });
   return Observable.concat(
     this.put(obj),
     Observable.from([FalcorJsonGraph.pathInvalidation([this.options.indexKey])])
   );
 }
 .flatMap(data =>
   Observable.concat(
     // Form needs to be initilized first with correct values else question inputs will be empty. TODO: find better solution.
     Observable.of(
       initialize('application', {
         characters: data.characters,
         questions: data.questions,
       }),
     ),
     Observable.of({
       type: GET_APPLICATION_TEMPLATE_SUCCESS,
       template: data,
     }),
   ),
示例#7
0
let logStream = Observable.create(observer => {
  // Create the subject if it doesn't exist already.
  if (logSubject === null) {
    logSubject = new LiteSubject<LogEntry>();
  }

  // An Observable representing buffered messages. Initialized to empty.
  let buffered: Observable<LogEntry> = Observable.empty<LogEntry>();

  // If the buffer exists, make it Observable.
  if (logBuffer !== null) {
    buffered = Observable.from(logBuffer);
    logBuffer = null;
  }

  // Combine (possibly empty) buffered messages with the subject, and pipe them to the
  // subscriber.
  return buffered
    .concat(logSubject.observable)
    .subscribe(observer);
});
示例#8
0
 const op: Operation = () => Observable
   .concat(
     copyExistingCacheOp(oldWorker, newWorker, url, cache)(),
     cacheFromNetworkOp(newWorker, url, cache)()
   )
   .take(1);