本文整理汇总了TypeScript中events.EventEmitter类的典型用法代码示例。如果您正苦于以下问题:TypeScript EventEmitter类的具体用法?TypeScript EventEmitter怎么用?TypeScript EventEmitter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EventEmitter类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('.get with invalid service name and arguments', done => {
const socket = new EventEmitter();
provider.emit('connection', socket);
socket.emit('get', null, (error: any) => {
assert.strictEqual(error.name, 'NotFound');
assert.strictEqual(error.message, `Service 'null' not found`);
done();
});
});
示例2: addHandler
function addHandler(emitter: EventEmitter, event: string, handler: (...args: Array<any>) => void) {
if (isLogEvent) {
emitter.on(event, (...args: Array<any>) => {
console.log("%s %s", event, args)
handler.apply(null, args)
})
}
else {
emitter.on(event, handler)
}
}
示例3: test
test('`waitUntilWatchIsReady` correctly handles `tsc` output', async () => {
buildOutputStream.emit('data', Buffer.from('$ tsc'));
buildOutputStream.emit('data', Buffer.from('Compilation complete.'));
jest.runAllTimers();
expect(await completionHintPromise).toBe('tsc');
});
示例4: test
test('`waitUntilWatchIsReady` fallbacks to default output handler if output is not recognizable', async () => {
buildOutputStream.emit('data', Buffer.from('$ some-cli'));
buildOutputStream.emit('data', Buffer.from('Compilation complete.'));
buildOutputStream.emit('data', Buffer.from('Chunk Names.'));
jest.runAllTimers();
expect(await completionHintPromise).toBe('timeout');
});
示例5: return
return () => {
bag.dispose();
if (input) {
input.removeAllListeners();
}
if (output) {
output.removeAllListeners();
}
};
示例6:
window.addEventListener("storage", (event) => {
if (event.key !== storageKey) return;
const oldPub = pub;
pub = JSON.parse(event.newValue);
if (oldPub.keyMap !== pub.keyMap) emitter.emit("keyMap");
if (oldPub.theme !== pub.theme) emitter.emit("theme");
});
示例7: resolve
return new Promise<any>((resolve, reject) => {
emitter.once(event, (value: any) => {
resolve(value);
});
emitter.once('error', (err: Error) => {
reject(err);
});
});
示例8: function
zoneA.run(() => {
emitter.on('removeListener', function(type: string, handler: any) {
zoneResults.push('remove' + type);
});
emitter.on('test', shouldNotRun);
emitter.on('test1', expectZoneA);
emitter.removeAllListeners('test');
expect(zoneResults).toEqual(['removetest']);
expect(emitter.listeners('removeListener').length).toBe(1);
});
示例9: function
response.on('end', function() {
try {
output = JSON.parse(content)
emitter.emit('done', output)
}
catch (e) {
e.cause = content
emitter.emit('error', e)
}
})