本文整理汇总了TypeScript中events.emit函数的典型用法代码示例。如果您正苦于以下问题:TypeScript emit函数的具体用法?TypeScript emit怎么用?TypeScript emit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了emit函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: default
export default (response: IncomingMessage, options: Options, emitter: EventEmitter) => {
const downloadBodySize = Number(response.headers['content-length']) || undefined;
const progressStream: TransformStream = downloadProgress(response, emitter, downloadBodySize);
mimicResponse(response, progressStream);
const newResponse = (
options.decompress === true &&
is.function_(decompressResponse) &&
options.method !== 'HEAD' ? decompressResponse(progressStream as unknown as IncomingMessage) : progressStream
) as Response;
if (!options.decompress && ['gzip', 'deflate', 'br'].includes(response.headers['content-encoding'] || '')) {
options.encoding = null;
}
emitter.emit('response', newResponse);
emitter.emit('downloadProgress', {
percent: 0,
transferred: 0,
total: downloadBodySize
});
response.pipe(progressStream);
};
示例2:
vscode.workspace.onDidChangeTextDocument(event => {
if (activeEditor && event.document === activeEditor.document) {
var contentChanges: vscode.TextDocumentContentChangeEvent[] = event.contentChanges;
// TODO also process multiple contentChanges (multi-cursor editing)
eventEmitter.emit('data', contentChanges[0].range.start);
}
}, null, context.subscriptions);
示例3: test
test('it restores saved highlights', done => {
const eventBus = new EventEmitter();
const savedDecorations = [{
pattern: {
type: 'string',
expression: 'PHRASE',
ignoreCase: false,
wholeMatch: false
},
color: '#F7E4B3'
}];
const configStore = mockType<ConfigStore>({savedHighlights: savedDecorations});
const decorationOperator = mock(DecorationOperator);
const decorationOperatorFactory = mock(DecorationOperatorFactory);
when(decorationOperatorFactory.createForVisibleEditors()).thenReturn(decorationOperator);
new SavedHighlightsRestorer(configStore, decorationOperatorFactory, matchingModeRegistry, eventBus);
eventBus.on(Event.EXTENSION_READY, () => {
verify(decorationOperator.addDecoration(new StringPattern({
phrase: 'PHRASE',
ignoreCase: false,
wholeMatch: false
}), '#F7E4B3'));
done();
});
eventBus.emit(Event.EXTENSION_READY);
});
示例4: start
async function start() {
events = [];
const { url } = await inquirer.prompt<{ url: string }>([
{
type: 'input',
name: 'url',
message:
'Enter the url you want to record, e.g https://react-redux.realworld.io: ',
},
]);
console.log(`Going to open ${url}...`);
await record(url);
console.log('Ready to record. You can do any interaction on the page.');
const { shouldReplay } = await inquirer.prompt<{ shouldReplay: boolean }>([
{
type: 'confirm',
name: 'shouldReplay',
message: `Once you want to finish the recording, enter 'y' to start replay: `,
},
]);
emitter.emit('done', shouldReplay);
const { shouldStore } = await inquirer.prompt<{ shouldStore: boolean }>([
{
type: 'confirm',
name: 'shouldStore',
message: `Persistently store these recorded events?`,
},
]);
if (shouldStore) {
saveEvents();
}
const { shouldRecordAnother } = await inquirer.prompt<{
shouldRecordAnother: boolean;
}>([
{
type: 'confirm',
name: 'shouldRecordAnother',
message: 'Record another one?',
},
]);
if (shouldRecordAnother) {
start();
} else {
process.exit();
}
}
示例5: test
test('it updates button appearance on receving case sensitivity mode change', done => {
const eventBus = new EventEmitter();
const statusBarItem = mockMethods<StatusBarItem>(['show']);
new ToggleCaseSensitivityModeButton(eventBus, statusBarItem);
eventBus.on(Event.TOGGLED_CASE_SENSITIVITY, () => {
assert.deepEqual(statusBarItem.text, 'Aa');
assert.deepEqual(statusBarItem.tooltip, 'TextMarker: Case Insensitive Mode');
verify(statusBarItem.show(), {times: 0});
done();
});
eventBus.emit(Event.TOGGLED_CASE_SENSITIVITY, {ignoreCase: true});
});
示例6: Buffer
router.post('/hooks/github', ctx => {
const body = JSON.stringify(ctx.request.body);
const hash = crypto.createHmac('sha1', secret).update(body).digest('hex');
const sig1 = new Buffer(ctx.headers['x-hub-signature']);
const sig2 = new Buffer(`sha1=${hash}`);
// シグネチャ比較
if (sig1.equals(sig2)) {
handler.emit(ctx.headers['x-github-event'], ctx.request.body);
ctx.status = 204;
} else {
ctx.status = 400;
}
});
示例7: sendMessage
function sendMessage(node, msg, done) {
"use strict";
node.log = function(msg) {
console.log(msg);
};
node.error = function(msg) {
console.log(msg);
done(msg);
};
node.send = function(msg) {
console.log(msg);
done();
};
nodeListener.emit("input", msg);
}
示例8: setImmediate
setImmediate( () => this.ee.emit('release') );