From dd59f0e5737abec72c41895b93365199fad66fcb Mon Sep 17 00:00:00 2001 From: Ali Mihandoost Date: Sun, 13 Mar 2022 02:31:31 +0330 Subject: [PATCH 1/2] fix(signal): promise to multi requests works --- package/signal/src/signal.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package/signal/src/signal.ts b/package/signal/src/signal.ts index 25668e948..b5b45bf3b 100644 --- a/package/signal/src/signal.ts +++ b/package/signal/src/signal.ts @@ -149,11 +149,12 @@ export class SignalInterface { */ request(requestParam: AlwatrRequestSignals[SignalName]): Promise { this._logger.logMethodArgs('request', {requestParam}); + const nextSignalValuePromise = this.getNextSignalValue(); _dispatchSignal( `request-${this.name}` as unknown as SignalName, requestParam as unknown as AlwatrSignals[SignalName], // mastmalize to avoid type error ); - return this.getNextSignalValue(); + return nextSignalValuePromise; } /** From fc3f9fdd8c76c6bc5117f3ee894480500f81cc80 Mon Sep 17 00:00:00 2001 From: Ali Mihandoost Date: Sun, 13 Mar 2022 02:31:43 +0330 Subject: [PATCH 2/2] feat(signal): demo as test --- demo/index.html | 5 ++++- demo/signal/index.html | 16 ++++++++++++++++ demo/signal/index.ts | 24 ++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 demo/signal/index.html create mode 100644 demo/signal/index.ts diff --git a/demo/index.html b/demo/index.html index 071af719e..41b94e423 100644 --- a/demo/index.html +++ b/demo/index.html @@ -7,6 +7,9 @@ - Logger +
    +
  1. Logger
  2. +
  3. Signal
  4. +
diff --git a/demo/signal/index.html b/demo/signal/index.html new file mode 100644 index 000000000..743cf9f9f --- /dev/null +++ b/demo/signal/index.html @@ -0,0 +1,16 @@ + + + + + + + + + +

Check the console

+ + + + + + diff --git a/demo/signal/index.ts b/demo/signal/index.ts new file mode 100644 index 000000000..e0fdca82c --- /dev/null +++ b/demo/signal/index.ts @@ -0,0 +1,24 @@ +import {SignalInterface} from '@alwatr/signal'; + +const signal = new SignalInterface('easter-egg'); + +signal.setProvider((param) => { + const newValue = param * 10; + console.info('2. signal provider called', {param, newValue}); + return newValue; +}); + +document.getElementById('requestButton')?.addEventListener('click', async () => { + console.info('1. request param: 1'); + const value = await signal.request(1); + console.info('3. new signal value', {value}); +}); + +document.getElementById('requestButton2')?.addEventListener('click', async () => { + console.info('1. request'); + const value1 = await signal.request(1); + console.info('3. 2x request'); + const value2p = signal.request(2); + const value3p = signal.request(3); + console.info('4. new signal value', {value1, value2: await value2p, value3: await value3p}); +});