本文整理汇总了TypeScript中rxjs.Observable.merge方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable.merge方法的具体用法?TypeScript Observable.merge怎么用?TypeScript Observable.merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rxjs.Observable
的用法示例。
在下文中一共展示了Observable.merge方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test
test('new game', function() {
expect(model(O.merge(
O.of({type: 'ROLL', payload: 1}),
O.of({type: 'NEW GAME'})
), mockProps$).skip(1).first()).toBeStreamOf(
['1', [1], true, false, mockProps]
);
expect(model(O.merge(
O.of({type: 'ROLL', payload: 1}),
O.of({type: 'NEW GAME'})
), mockProps$).last()).toBeStreamOf(
['', [], true, false, mockProps]
);
});
示例2: constructor
constructor() {
this.toggleLeftPane = new Rx.Subject<boolean>();
this.focusInputBox = new Rx.Subject<void>();
this.focusWindow = new Rx.Subject<void>();
this.selectChannel = new Rx.Subject<ChannelId>();
this.setQuitConfirmDialog = new Rx.Subject<void>();
this.showConnectSetting = new Rx.Subject<void>();
this.showGeneralSetting = new Rx.Subject<void>();
this.showSignIn = new Rx.Subject<void>();
this.showLatestInChannel = new Rx.Subject<ChannelId>();
this.tryCloseChannel = new Rx.Subject<ChannelId>();
this.toggleInlineImage = new Rx.Subject<void>();
this.showSomeSettings = Rx.Observable.merge<SettingId, SettingId>(...[
this.showSignIn.map(function() { return 'sign-in'; }),
this.showConnectSetting.map(function() { return 'connect'; }),
this.showGeneralSetting.map(function() { return 'settings'; }),
]);
}
示例3: it
it('should hide responses from outside the scope', function(done) {
const proxyRequest$ = new Rx.Subject();
function main(sources: {HTTP: HTTPSource}) {
return {
HTTP: proxyRequest$,
};
}
const {sources, run} = Cycle.setup(main, {HTTP: makeHTTPDriver()});
const ignoredRequest$ = Rx.Observable.of(uri + '/json');
const request$ = Rx.Observable.of(uri + '/hello').delay(10);
const scopedRequest$ = sources.HTTP.isolateSink(request$, 'foo');
const scopedHTTPSource = sources.HTTP.isolateSource(sources.HTTP, 'foo');
scopedHTTPSource.select().subscribe(function(response$) {
assert.strictEqual(typeof response$.request, 'object');
assert.strictEqual(response$.request.url, uri + '/hello');
response$.subscribe(function(response) {
assert.strictEqual(response.status, 200);
assert.strictEqual(response.text, 'Hello World');
done();
});
});
Rx.Observable
.merge(ignoredRequest$, scopedRequest$)
.subscribe(proxyRequest$);
run();
});
示例4: it
it('should remove old paths', () => {
const data = ['a', 'b', 'c'];
const data2 = ['a', 'b'];
let callback: (paths: string[]) => void;
const tracker = new ProjectTracker({
getPaths() { return data; },
onDidChangePaths(cb) {
callback = cb;
return { dispose() { /* */ } };
}
});
return Observable.merge(
tracker.removed
.take(1),
tracker.added
.take(3)
.subscribeOn(Scheduler.async)
.do({
complete() {
callback(data2);
}
})
)
.take(4)
.toArray()
.toPromise()
.then(values => {
expect(values).to.deep.eq(['a', 'b', 'c', 'c']);
});
});
示例5: disconnected
disconnected(): Rx.Observable<void> {
const args = [
this._socket.connectError(),
this._socket.disconnect(),
];
return Rx.Observable.merge<void, void>(...args);
}
示例6: main
function main({DOM}) {
const username$ = DOM.select('#username').events('input');
const password$ = DOM.select('#password').events('input');
const loginButton$ = DOM.select('#login').events('click');
const form$ = O.combineLatest(
username$.map(e => e.target.value),
password$.map(e => e.target.value),
(username, password) => ({username, password})
);
const action$: O<any> = O.merge(
form$.map( formData => loginButton$.mapTo((
{ type: 'LOGIN', payload: formData }
))).switch()
).distinctUntilChanged();
const reducer$ = O.merge(
action$
.filter((action) => action.type === 'LOGIN')
.map(action => function loginReducer(state) {
return state +
`$$$ login(${action.payload.username}, ${action.payload.password})`;
})
);
const state$ = reducer$.scan((state, next) => next(state), '')
.startWith('');
return {DOM: state$.map(state =>
div('.container', {props: {style: 'margin: 1pc'}}, [
div(state),
div('.form', {props: {style: 'outline: 1pt solid blue; padding: 1pc'}}, [
div('.form-group', [
label({props: {for: 'username'}}, 'Username'),
input('#username.form-control', {props: {type: 'text', autofocus: true}}),
]),
div('form-group', [
label({props: {for: 'password'}}, 'Password'),
input('#password.form-control', {props: {type: 'password'}}),
]),
hr(),
div('.form-group', [
button('#login.form-control.btn.btn-primary', 'Log In')
])
])
])
)};
}
示例7: it
it('deve executar multiplas operaçþes assincronas em conjunto', done => {
Observable.merge<number>(operacaoAssincrona(10), operacaoAssincrona(20))
.filter(response => !!(response % 2))
.toArray()
.subscribe(response => {
expect(response).to.deep.equal([1, 3, 5, 7, 9, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19]);
}, null, done);
});
示例8: subscribeUsers
subscribeUsers(): Subscription {
// Fetch all users matching search pattern
const subscription = MeteorObservable.subscribe('users', this.searchPattern.getValue());
const autorun = MeteorObservable.autorun();
return Observable.merge(subscription, autorun).subscribe(() => {
this.users = this.findUsers();
});
}