本文整理匯總了TypeScript中rxjs/Rx.Observable.zip方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Observable.zip方法的具體用法?TypeScript Observable.zip怎麽用?TypeScript Observable.zip使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rxjs/Rx.Observable
的用法示例。
在下文中一共展示了Observable.zip方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: handleHighResImageLoad
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)
}
}
示例2:
.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})
)
示例3: getEventLoops
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);
}
示例4: constructor
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);
});
}
示例5: BehaviorSubject
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$;
};
示例6: if
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
}
});
示例7: constructor
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 => {
//.........這裏部分代碼省略.........
示例8:
.mergeMap((todo) => {
return Observable.zip(
this.detail(todo.id),
this.newestEpisode(todo.id),
(detail, episode) => ({ id: todo.id, todo, detail, episode }));
})
示例9:
.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 }))
示例10: function
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};
});
});