當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript events.emit函數代碼示例

本文整理匯總了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);
};
開發者ID:sindresorhus,項目名稱:got,代碼行數:27,代碼來源:get-response.ts

示例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);
開發者ID:duog,項目名稱:vscode-haskell,代碼行數:7,代碼來源:extension.ts

示例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);
    });
開發者ID:ryu1kn,項目名稱:vscode-text-marker,代碼行數:28,代碼來源:saved-highlights-restorer.test.ts

示例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();
    }
  }
開發者ID:aftabnaveed,項目名稱:rrweb,代碼行數:53,代碼來源:repl.ts

示例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});
    });
開發者ID:ryu1kn,項目名稱:vscode-text-marker,代碼行數:13,代碼來源:toggle-case-sensitivity-mode.test.ts

示例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;
		}
	});
開發者ID:ha-dai,項目名稱:Misskey,代碼行數:14,代碼來源:github.ts

示例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);
}
開發者ID:markrey,項目名稱:node-red-contrib-oracledb,代碼行數:15,代碼來源:oracledb.spec.ts

示例8: setImmediate

		setImmediate( () => this.ee.emit('release') );
開發者ID:BelaPlatform,項目名稱:Bela,代碼行數:1,代碼來源:Lock.ts


注:本文中的events.emit函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。