本文整理匯總了TypeScript中rxjs.fromEventPattern函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript fromEventPattern函數的具體用法?TypeScript fromEventPattern怎麽用?TypeScript fromEventPattern使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了fromEventPattern函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('should send errors in the selector down the error path', (done: MochaDone) => {
let target: any;
const trigger = (value: any) => {
if (target) {
target(value);
}
};
const addHandler = (handler: any) => {
target = handler;
};
const removeHandler = (handler: any) => {
target = null;
};
const selector = (x: any) => {
throw 'bad';
};
fromEventPattern(addHandler, removeHandler, selector)
.subscribe((x: any) => {
done(new Error('should not be called'));
}, (err: any) => {
expect(err).to.equal('bad');
done();
}, () => {
done(new Error('should not be called'));
});
trigger('test');
});
示例2: addHandler
('should create an observable from the handler API', () => {
function addHandler(h: any) {
timer(50, 20, rxTestScheduler).pipe(
mapTo('ev'),
take(2),
concat(NEVER)
).subscribe(h);
}
const e1 = fromEventPattern(addHandler);
const expected = '-----x-x---';
expectObservable(e1).toBe(expected, {x: 'ev'});
});
示例3: fromEventPattern
observable1 = constructorZone1.run(() => {
return fromEventPattern(
(handler: any) => {
expect(Zone.current.name).toEqual(constructorZone1.name);
button.addEventListener('click', handler);
log.push('addListener');
},
(handler: any) => {
expect(Zone.current.name).toEqual(constructorZone1.name);
button.removeEventListener('click', handler);
document.body.removeChild(button);
log.push('removeListener');
});
});
示例4: addHandler
export function fromHistory<LocationState>(
history: History
): Observable<[Location<LocationState>, Action]> {
let unregisterCallback: UnregisterCallback;
function addHandler(handler: LocationListener): void {
unregisterCallback = history.listen(handler);
handler(history.location, history.action);
}
function removeHandler(): void {
if (unregisterCallback) {
unregisterCallback();
}
}
return fromEventPattern<[Location<LocationState>, Action]>(
addHandler,
removeHandler
);
}