-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from AliMD/fix/signal
[Signal] Fix multi request and add demo
- Loading branch information
Showing
4 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title></title> | ||
</head> | ||
|
||
<body> | ||
<h3>Check the console</h3> | ||
<button id="requestButton">Request Signal</button> | ||
<button id="requestButton2">3x Request Signal</button> | ||
<script src="./index.js" type="module"></script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters