private handleHighResImageLoad(fullResImage){
		if (!fullResImage) {
			return;
		}

		const image = new Image();
		image.src = fullResImage;

		if (!image.complete) {
			const onLoadObservable = Observable.create(obs => {
				image.onload = () => {
					obs.next(image);
					obs.complete();
				}
			});

			// We want the animation to finish before replacing the pic
			// as the calculation has been done with the smaller image
			Observable.zip(onLoadObservable, this.didEnter)
				.subscribe(() => this.instance.updateImageSrcWithTransition(fullResImage));

		} else {
			this.instance.updateImageSrc(fullResImage)
		}
	}
 .concatMap<{errors: string[], config: {[key: string]: string}, appSettings: {[key: string]: string} }>(() =>
     Observable.zip(
         this._functionsService.getHostErrors().catch(e => Observable.of([])),
         this._armService.getConfig(this._globalStateService.FunctionContainer),
         this._armService.getFunctionContainerAppSettings(this._globalStateService.FunctionContainer),
         (e,  c, a) => ({errors: e, config: c, appSettings: a})
     )
Exemplo n.º 3
0
  getEventLoops(event: EventModel): Observable<TrackModel[]> {
    if (!event) {
      return Observable.of([]);
    }

    const loopObservables: Observable<TrackModel>[] = _([event.loop1, event.loop2, event.loop3])
      .filter((loopId: string) => loopId)
      .map((loop: string) => this.getTrack(loop))
      .value();

    if (loopObservables.length === 0) {
      return Observable.of([]);
    }

    return Observable.zip(...loopObservables);
  }
Exemplo n.º 4
0
  constructor(
    dispatcher$: Dispatcher<Action>
  ) {
    const initState: AppState = {
      heroes: initialHeroes
    };
    this.stateSubject$ = new BehaviorSubject(initState);

    Observable
      .zip<AppState>(
      heroReducer(initState.heroes, dispatcher$),
      (heroes) => {
        return { heroes } as AppState;
      }
      )
      .subscribe(appState => {
        this.stateSubject$.next(appState);
      });
  }
Exemplo n.º 5
0
export const stateFn = (initial: AppState, action$: Observable<Action>): Observable<AppState> => {
    const subject$ = new BehaviorSubject(initial);
    Observable
        .zip(
            todosReducer(initial.todos, action$),
            filtersReducer(initial.filters, action$),
            logReducer(initial.log, action$),
            (todos, filters, log) => {
                return {
                    todos,
                    filters,
                    log
                } as AppState;
            }
        )
        .do(v => console.log(v))
        .subscribe(state => {
            subject$.next(state);
        });
    return subject$;
};
Exemplo n.º 6
0
    dragulaService.drop.subscribe(([bag, element, target, source, next]) => {
      // Look at the adjacent tasks in the list and pick a priority in the middle
      let prev = element.previousElementSibling;

      if (bag === 'taskBag') {
        let observables: Observable<Task>[] = [Observable.of(undefined), Observable.of(undefined), Observable.of(undefined)];
        // Get the keys from the DOM. Stored in data-key attributes.
        if (prev != null && prev.className === 'task') observables[0] = (af.object(this.boardURL + '/tasks/' + prev.dataset.key));
        if (element != null && element.className === 'task') observables[1] = (af.object(this.boardURL + '/tasks/' + element.dataset.key));
        if (next != null && next.className === 'task') observables[2] = (af.object(this.boardURL + '/tasks/' + next.dataset.key));

        Observable.zip(...observables) // Combine the observables then subscribe asynchronously
          .take(1) // only subscribe once
          .subscribe(([previousTask, movedTask, nextTask]: Task[]) => {
            let lower = -4; // arbitrary
            let upper = 4;  // arbitrary
            if (previousTask && previousTask.priority != null) {
              lower = previousTask.priority;
            } else if (nextTask && nextTask.priority != null) {
              lower = nextTask.priority - 4;
            }
            if (nextTask && nextTask.priority != null) {
              upper = nextTask.priority;
            } else if (previousTask && previousTask.priority != null) {
              upper = previousTask.priority + 4;
            }
            // Update the priority of the moved task in the database
            movedTask.priority = lower + (Math.abs(upper - lower) / 2);
            // Check if it swapped to a different list
            if (target.dataset.key !== source.dataset.key) {
              movedTask.list = target.dataset.key;
            }
            this.taskObservable.update(element.dataset.key, movedTask);
          });
      } else if (bag === 'listBag') {
        // TODO reorder the lists, similar as above
      }
    });
Exemplo n.º 7
0
    constructor(todoStore: TodoStorage) {
        super([
            "areAllTodosComplete",
            "todos",
            "editedTodo",
            "newTodo",
            "status",
            "_visibleTodos",
            "remainingText"
        ]);
        this._store = todoStore;
        this.editedTodo = null;
        this.newTodo = new Todo();
        this.todos = new ReactiveArray<Todo>();
        this.areAllTodosComplete = false;
        this.completedTodos = this.todos.derived.whenAnyItemProperty().filter(t => t.completed).build();
        this.incompleteTodos = this.todos.derived.whenAnyItemProperty().filter(t => !t.completed).build();
        this.save = ReactiveCommand.createFromTask((a) => {
            return this._store.putTodos(this.todos.toArray());
        });

        var isNotSaving = this.save.isExecuting.map(executing => !executing);

        this.loadTodos = ReactiveCommand.createFromTask((a) => {
            return this._store.getTodos();
        });
        this.loadTodos.results.subscribe(todos => {
            this.todos.splice(0, this.todos.length, ...todos);
        });

        this.deleteTodo = ReactiveCommand.createFromObservable((a: Todo) => {
            var todoIndex = this.todos.indexOf(a);
            if (todoIndex >= 0) {
                this.todos.splice(todoIndex, 1);
                return this.save.execute();
            } else {
                return Observable.of(false);
            }
        });

        this.toggleTodo = ReactiveCommand.createFromObservable((todo: Todo) => {
            todo.completed = !todo.completed;
            return this.save.execute();
        }, isNotSaving);

        var hasValidNewTodo = this.whenAnyValue(vm => vm.newTodo.title)
            .map(title => this.isValidTitle(title));

        var canAddTodo = Observable.combineLatest(
            hasValidNewTodo,
            isNotSaving,
            (validTodo, isNotSaving) => validTodo && isNotSaving);

        this.addTodo = ReactiveCommand.createFromObservable((a) => {
            this.newTodo.title = this.newTodo.title.trim();
            this.todos.unshift(this.newTodo.copy());
            this.resetNewTodo();
            return this.save.execute();
        }, canAddTodo);

        this.editTodo = ReactiveCommand.create((todo: Todo) => {
            this._originalTodo = todo.copy();
            this.editedTodo = todo;
            return {};
        });

        this.finishEditing = ReactiveCommand.createFromObservable(a => {
            if (this.editedTodo) {
                this.editedTodo.title = this.editedTodo.title.trim();
                if (this.editedTodo.title.length == 0) {
                    return this.deleteTodo.execute(this.editedTodo);
                }
                this.editedTodo = null;
            }
            return this.save.execute().do(saved => {
                if (saved) {
                    this._originalTodo = null;
                    this.editedTodo = null;
                }
            });
        }, isNotSaving);

        var canUndo = this.whenAnyValue(vm => vm.editedTodo, vm => vm.todos, (e, todos) => e !== null && todos !== null);

        this.undo = ReactiveCommand.create(a => {
            if (this.editedTodo && this._originalTodo) {
                this.editedTodo.title = this._originalTodo.title;
                this.editedTodo.completed = this._originalTodo.completed;
            }
            this.editedTodo = null;
            this._originalTodo = null;
            return true;
        }, canUndo);

        var areAllComplete = this.todos.computed.every(t => t.completed);
        var hasTodos = this.todos.whenAnyValue(t => t.length).map(length => length > 0);
        var canMarkAllComplete = Observable.combineLatest(hasTodos, areAllComplete, isNotSaving, (hasTodos, complete, notSaving) => hasTodos && !complete && notSaving);
        var canMarkAllIncomplete = Observable.combineLatest(hasTodos, areAllComplete, isNotSaving, (hasTodos, complete, notSaving) => hasTodos && complete && notSaving);
        Observable.zip(hasTodos, areAllComplete, (hasTodos, complete) => hasTodos && complete)
            .subscribe(complete => {
                this.areAllTodosComplete = complete;
            });

        this.markAllComplete = ReactiveCommand.createFromObservable(a => {
            var completedTodos = this.todos;
            completedTodos.forEach(t => {
                t.completed = true;
            });
            return this.save.execute();
        }, canMarkAllComplete);

        this.markAllIncomplete = ReactiveCommand.createFromObservable(a => {
            var incompleteTodos = this.todos;
            incompleteTodos.forEach(t => {
                t.completed = false;
            });
            return this.save.execute();
        }, canMarkAllIncomplete);

        this.toggleAllComplete = ReactiveCommand.createFromObservable(a => {
            var allComplete = this.todos.every(t => t.completed);
            if (allComplete) {
                return this.markAllIncomplete.execute();
            } else {
                return this.markAllComplete.execute();
            }
        }, isNotSaving);

        this.clearComplete = ReactiveCommand.createFromObservable(a => {
            var todos = this.todos;
            for (var i = todos.length - 1; i >= 0; i--) {
                var t = todos.getItem(i);
                if (t.completed) {
                    todos.splice(i, 1);
                }
            }
            return this.save.execute();
        }, isNotSaving);

        this.whenAnyValue(vm => vm.todos, vm => vm.status, (todos, status) => ({ todos, status }))
            .filter(args => args.todos !== null)
            .map(args => {
                if (args.status === "all") {
                    return args.todos;
                } else if (args.status === "complete") {
                    return args.todos.derived.whenAnyItemProperty().filter(t => t.completed).build();
                } else {
                    return args.todos.derived.whenAnyItemProperty().filter(t => !t.completed).build();
                }
            }).subscribe(todos => {
                this._visibleTodos = todos;
            });
        this.whenAnyValue(vm => vm._visibleTodos)
            .map(arr => arr.toObservable())
            .switch()
            .subscribe(arr => {
                this.set("visibleTodos", arr);
            });
        this.incompleteTodos.whenAnyValue(incomplete => incomplete.length)
            .map(l => l === 1 ? 'item left' : 'items left')
            .subscribe(text => this.remainingText = text);
        this.status = "all";
    }
Exemplo n.º 8
0
 .mergeMap((todo) => {
   return Observable.zip(
     this.detail(todo.id),
     this.newestEpisode(todo.id),
     (detail, episode) => ({ id: todo.id, todo, detail, episode }));
 })
 .switchMap(fi =>
     Observable.zip(
         this._functionsService.getFileContent(fi.script_href),
         fi.clientOnly ? Observable.of({}) : this._functionsService.getSecrets(fi),
         this._functionsService.getFunction(fi),
         (c, s, f) => ({ content: c, secrets: s, functionInfo: f }))
Exemplo n.º 10
0
 const observable3: any = constructorZone1.run(() => {
   return Rx.Observable.zip(observable1, observable2, function(n: number, str: string) {
     expect(Zone.current.name).toEqual(constructorZone1.name);
     return {n: n, str: str};
   });
 });