本文整理匯總了TypeScript中rxjs/Subject.Subject.merge方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Subject.merge方法的具體用法?TypeScript Subject.merge怎麽用?TypeScript Subject.merge使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rxjs/Subject.Subject
的用法示例。
在下文中一共展示了Subject.merge方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: function
impl: function(context,params,databind,base) {
if (jbart.location) return;
if (!databind || typeof databind != 'object')
return console.log('no databind for rx.url-path')
var browserUrlEm = new Subject();
jbart.location = History.createHistory();
jbart.location.path = () => location.pathname;
jbart.location.listen(x=>
browserUrlEm.next(x.pathname))
function urlToObj(path) {
var vals = path.substring(path.indexOf(base) + base.length).split('/')
.map(x=>decodeURIComponent(x))
var res = {};
params.forEach((p,i) =>
res[p] = (vals[i+1] || ''));
return res;
}
function objToUrl(obj) {
var split_base = jbart.location.path().split(`/${base}`);
var url = split_base[0] + `/${base}/` +
params.map(p=>obj[p]||'')
.join('/');
return url.replace(/\/*$/,'');
}
var databindEm = context.vars.ngZone.onStable // .onUnstable
.map(()=>databind)
.filter(obj=>
obj.project)
.map(obj=>
objToUrl(obj));
browserUrlEm.merge(databindEm)
.startWith(jbart.location.path())
.distinctUntilChanged()
.subscribe(url => {
jbart.location.push(url);
jb.extend(databind,urlToObj(url));
context.params.onUrlChange(context.setData(url));
})
}
示例2: it
it('should work', () => {
const subject1 = new Subject<string>();
const subject2 = new Subject<string>();
const observable = subject1.merge(subject2);
const log = [];
observable.subscribe(next => log.push(next));
subject1.next('hello');
expect(log).toEqual(['hello']);
subject2.next('world');
expect(log).toEqual(['hello', 'world']);
subject2.next('!');
expect(log).toEqual(['hello', 'world', '!']);
subject1.next('!!');
expect(log).toEqual(['hello', 'world', '!', '!!']);
});