本文整理汇总了TypeScript中jb-ui/jb-rx.Observable类的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable类的具体用法?TypeScript Observable怎么用?TypeScript Observable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Observable类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getProbe
function getProbe() {
if (cmp.probeResult)
return [cmp.probeResult];
var _probe = jb_rx.Observable.fromPromise(ctx.run({$: 'studio.probe', path: ctx.params.path }));
_probe.subscribe(res=>
cmp.probeResult = res);
// do not wait more than 500 mSec
return _probe.race(jb_rx.Observable.of({finalResult: [ctx] }).delay(500))
.catch(e=>
jb.logException(e,'in probe exception'))
}
示例2: compAsStr
impl : (ctx,force) =>
jb_rx.Observable.from(jb.entries(modified))
.filter(x=>x)
.concatMap(toSave=>{
var comp = toSave[0], val = toSave[1];
message('saving ' + comp);
if (force && !val.original)
val.original = `jb.component('${comp}', {`;
return $.ajax({
url: `/?op=saveComp&comp=${comp}&project=${ctx.exp('%$globals/project%')}&force=${force}`,
type: 'POST',
data: JSON.stringify({ original: val && val.original, toSave: compAsStr(comp) }),
headers: { 'Content-Type': 'application/json; charset=UTF-8' }
}).then(
res=>({ res: res , comp: comp }),
e=> { throw { e: e , comp: comp } }
)
// return fetch(`/?op=saveComp&comp=${comp}&project=${ctx.exp('%$globals/project%')}&force=${force}`, {
// method: 'post',
// body: JSON.stringify({ original: val && val.original, toSave: compAsStr(comp) }),
// headers: { 'Content-type': 'application/json; charset=UTF-8' },
// })
})
.catch(e=>{
message('error saving: ' + e.e);
jb.logException(e,'error while saving ' + e.comp)
})
.subscribe(entry=>{
var result = entry.res;
message((result.type || '') + ': ' + (result.desc || '') + (result.message || ''), result.type != 'success');
if (result.type == 'success')
delete modified[entry.comp];
})
示例3:
beforeInit: cmp => {
cmp.jbWatchGroupChildrenEm = (cmp.jbWatchGroupChildrenEm || jb_rx.Observable.of())
.merge(cmp.jbEmitter
.filter(x => x == 'check')
.merge(
pathChangesEm.takeUntil( cmp.jbEmitter.filter(x=>x =='destroy') ).do(fixer=>
jb.writeValue(path_ref,fixer.fix(jb.val(path_ref))))
)
.map(()=> jb.val(path_ref))
.distinctUntilChanged()
.map(val=> {
var ctx2 = (cmp.refreshCtx ? cmp.refreshCtx() : cmp.ctx);
return context.vars.$model.controls(ctx2)
})
)
},
示例4: CompOption
afterViewInit: cmp=> {
var input = $(cmp.elementRef.nativeElement).findIncludeSelf('input')[0];
if (!input)
return;
suggestionCtx.input = input;
var inputClosed = cmp.jbEmitter.filter(x=>x =='destroy');
cmp.keyEm = jb_rx.Observable.fromEvent(input, 'keydown')
.takeUntil(inputClosed);
suggestionCtx.keyEm = cmp.keyEm;
suggestionCtx.closeAndWriteValue = _ =>{
ctx.params.closeFloatingInput();
var option = input.value.indexOf('=') == 0 ? new CompOption(input.value.substr(1)) : new ValueOption();
option.writeValue(cmp.ctx);
};
suggestionCtx.refresh = _ =>
cmp.changeDt.detectChanges();
cmp.keyEm.filter(e=> e.keyCode == 13)
.subscribe(e=>{
if (!suggestionCtx.show || suggestionCtx.options.length == 0)
suggestionCtx.closeAndWriteValue()
})
cmp.keyEm.filter(e=> e.keyCode == 27)
.subscribe(e=>{
ctx.params.closeFloatingInput();
})
suggestionCtx.suggestionEm = cmp.keyEm
.filter(e=> e.keyCode != 38 && e.keyCode != 40 && e.key != 'Shift')
.delay(1) // we use keydown - let the input fill itself
.debounceTime(20) // solves timing of closing the floating input
.filter(e=>
suggestionCtx.show = new suggestions(input,ctx.params.expressionOnly).suggestionsRelevant() )
.catch(e=>
console.log(1,e))
.map(e=>
input.value)
// .do(x=>console.log(0,x))
.distinctUntilChanged()
// .do(x=>console.log(1,x))
.flatMap(e=>
getProbe())
.map(res=>
res && res.finalResult && res.finalResult[0] && res.finalResult[0].in)
.map(probeCtx=>
new suggestions(input,ctx.params.expressionOnly).extendWithOptions(probeCtx,ctx.params.path))
.catch(e=>
console.log(2,e))
.distinctUntilChanged((e1,e2)=>
e1.key == e2.key)
.do(e=>jb_logPerformance('suggestions',e))
.catch(e=>
console.log(3,e))
function getProbe() {
if (cmp.probeResult)
return [cmp.probeResult];
var _probe = jb_rx.Observable.fromPromise(ctx.run({$: 'studio.probe', path: ctx.params.path }));
_probe.subscribe(res=>
cmp.probeResult = res);
// do not wait more than 500 mSec
return _probe.race(jb_rx.Observable.of({finalResult: [ctx] }).delay(500))
.catch(e=>
jb.logException(e,'in probe exception'))
}
}