本文整理匯總了TypeScript中events.on函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript on函數的具體用法?TypeScript on怎麽用?TypeScript on使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了on函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: 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);
});
示例2: 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});
});
示例3: Promise
return new Promise( resolve => {
// if the lock is free, lock it immediately
if (!this.locked){
this.locked = true;
// console.log('lock acquired');
return resolve();
}
// otherwise sleep the thread and register a callback for when the lock is released
let reacquire = () => {
if (!this.locked){
this.locked = true;
// console.log('lock acquired');
this.ee.removeListener('release', reacquire);
return resolve();
}
};
this.ee.on('release', reacquire);
});
示例4: function
node.on = function (event, action) {
nodeListener.on(event, action);
};
示例5: switch
handler.on('status', event => {
const state = event.state;
switch (state) {
case 'error':
case 'failure':
const commit = event.commit;
const parent = commit.parents[0];
// Fetch parent status
request({
url: `${parent.url}/statuses`,
headers: {
'User-Agent': 'misskey'
}
}, (err, res, body) => {
if (err) {
console.error(err);
return;
}
const parentStatuses = JSON.parse(body);
const parentState = parentStatuses[0].state;
const stillFailed = parentState == 'failure' || parentState == 'error';
if (stillFailed) {
post(`**â ď¸BUILD STILL FAILEDâ ď¸**: ?[${commit.commit.message}](${commit.html_url})`);
} else {
post(`**đ¨BUILD FAILEDđ¨**: âââ?[${commit.commit.message}](${commit.html_url})âââ`);
}
});
break;
}
});