本文整理汇总了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', '!', '!!']);
});