本文整理匯總了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') );