-
Notifications
You must be signed in to change notification settings - Fork 0
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 #13 from Olian04/11-change-internals-to-use-weak-r…
…eferences Change internals to use weak references
- Loading branch information
Showing
34 changed files
with
703 additions
and
347 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const { MochaOptions } = require('mocha'); | ||
|
||
/** @type {MochaOptions} */ | ||
module.exports = { | ||
spec: ['./tests/**/*.test.ts'], | ||
require: 'ts-node/register', | ||
recursive: true, | ||
}; |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.gitignore | ||
.editorconfig | ||
.mocharc.js | ||
rollup.config.mjs | ||
tsconfig.json | ||
.vscode | ||
|
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,69 @@ | ||
<!DOCTYPE html> | ||
<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>Simply Reactive</title> | ||
</head> | ||
<body> | ||
<div> | ||
<span id="out-a"></span> | ||
* | ||
<span id="out-b"></span> | ||
= | ||
<span id="out-product"></span> | ||
</div> | ||
<lable> | ||
A: | ||
<input id="in-a" /> | ||
</lable> | ||
<lable> | ||
B: | ||
<input id="in-b" /> | ||
</lable> | ||
|
||
<button id="destroy-btn">Destroy</button> | ||
<button id="restore-btn">Restore</button> | ||
|
||
<script src="../cdn/simply-reactive.js"></script> | ||
<script> | ||
const { createAtom, createSelector, createEffectGroup } = simplyReactive; | ||
|
||
const A = createAtom({ | ||
default: 2, | ||
}); | ||
|
||
const B = createAtom({ | ||
default: 3, | ||
}); | ||
|
||
const Prod = createSelector({ | ||
get: () => A.get() * B.get(), | ||
}); | ||
|
||
document.getElementById('in-a').value = A.get(); | ||
document.getElementById('in-a').addEventListener('change', (ev) => { | ||
A.set(parseInt(ev.target.value, 10)); | ||
}); | ||
|
||
document.getElementById('in-b').value = B.get(); | ||
document.getElementById('in-b').addEventListener('change', (ev) => { | ||
B.set(parseInt(ev.target.value, 10)); | ||
}); | ||
|
||
const Effect = createEffectGroup([ | ||
() => (document.getElementById('out-a').innerText = A.get()), | ||
() => (document.getElementById('out-b').innerText = B.get()), | ||
() => (document.getElementById('out-product').innerText = Prod.get()), | ||
]); | ||
|
||
document.getElementById('destroy-btn').addEventListener('click', () => { | ||
Effect.destroy(); | ||
}); | ||
document.getElementById('restore-btn').addEventListener('click', () => { | ||
Effect.restore(); | ||
}); | ||
</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
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
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,34 @@ | ||
import { getNextAutoKey } from '../globals'; | ||
import { createEffect } from '../primitives/createEffect'; | ||
import { Effect } from '../types/Effect'; | ||
import { EffectGroup } from '../types/EffectGroup'; | ||
import { EffectProps } from '../types/EffectProps'; | ||
|
||
export const createEffectGroup = ( | ||
effectCallbacks: EffectProps.Callback[], | ||
config?: Partial<EffectProps.Config> | ||
): EffectGroup => { | ||
const key = config?.key || getNextAutoKey(); | ||
|
||
const effects: Effect[] = effectCallbacks.map((cb, index) => | ||
createEffect(cb, { | ||
debounceDuration: config?.debounceDuration, | ||
key: `${key}_effect_${index}`, | ||
}) | ||
); | ||
|
||
const api = { | ||
key, | ||
destroy: () => { | ||
effects.forEach((effect) => { | ||
effect.destroy(); | ||
}); | ||
}, | ||
restore: () => { | ||
effects.forEach((effect) => { | ||
effect.restore(); | ||
}); | ||
}, | ||
}; | ||
return api; | ||
}; |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.