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