本文整理匯總了TypeScript中jb-ui/jb-rx.Observable.fromEvent方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Observable.fromEvent方法的具體用法?TypeScript Observable.fromEvent怎麽用?TypeScript Observable.fromEvent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類jb-ui/jb-rx.Observable
的用法示例。
在下文中一共展示了Observable.fromEvent方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: suggestions
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'))
}
}