本文整理匯總了TypeScript中@phosphor/signaling.ISignal.connect方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript ISignal.connect方法的具體用法?TypeScript ISignal.connect怎麽用?TypeScript ISignal.connect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@phosphor/signaling.ISignal
的用法示例。
在下文中一共展示了ISignal.connect方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: Array
export function signalToPromises<T, U>(
signal: ISignal<T, U>,
numberValues: number
): Promise<[T, U]>[] {
const values: Promise<[T, U]>[] = new Array(numberValues);
const resolvers: Array<(value: [T, U]) => void> = new Array(numberValues);
for (let i = 0; i < numberValues; i++) {
values[i] = new Promise<[T, U]>(resolve => {
resolvers[i] = resolve;
});
}
let current = 0;
function slot(sender: T, args: U) {
resolvers[current++]([sender, args]);
if (current === numberValues) {
cleanup();
}
}
signal.connect(slot);
function cleanup() {
signal.disconnect(slot);
}
return values;
}
示例2: catch
export function testEmission<T, U, V>(
signal: ISignal<T, U>,
options: {
find?: (a: T, b: U) => boolean;
test?: (a: T, b: U) => void;
value?: V;
}
): Promise<V> {
const done = new PromiseDelegate<V>();
const object = {};
signal.connect((sender: T, args: U) => {
if (!options.find || options.find(sender, args)) {
try {
Signal.disconnectReceiver(object);
if (options.test) {
options.test(sender, args);
}
} catch (e) {
done.reject(e);
}
done.resolve(options.value || undefined);
}
}, object);
return done.promise;
}