Created
December 15, 2020 08:34
-
-
Save WebReflection/9c2e09ef712807165ae98158236abb0c to your computer and use it in GitHub Desktop.
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
function useState(value) { | |
const {caller} = arguments.callee; | |
const {arguments: a} = caller; | |
const {stack} = useState; | |
if (!stack.has(caller)) | |
stack.set(caller, {a, i: 0, s: []}); | |
const state = stack.get(caller); | |
state.a = a; | |
const {i, s} = state; | |
if (i === s.length) { | |
s.push([value, value => { | |
s[i][0] = value; | |
state.i = 0; | |
caller.apply(null, a); | |
}]); | |
} | |
return s[state.i++]; | |
} | |
useState.stack = new WeakMap; | |
function any() { | |
const [a, updateA] = useState(0); | |
const [b, updateB] = useState(0); | |
console.log(a, b); | |
if (!b) | |
updateB(1); | |
} | |
any(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment