We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
我刚刚学react,看见您写的小书对我帮助很大。感谢 function createStore(s,stateChanger) { const listeners = [] const queue = [] let state = s const getState = () => state let timerId :any = 0 const dispatch = (action) => { if(typeof action == 'function') { const d = stateChanger(state,action()) for(const value of listeners) { value(d) state = d } return; } queue.push(() => { return stateChanger(state,action) }) clearImmediate(timerId) timerId = setImmediate (() => { let d = null while (queue.length) { d = queue.shift()() state = d } for(const value of listeners) { value(d) } },1) } const subscribe = (listen) => listeners.push(listen) return { getState,dispatch,subscribe } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
我刚刚学react,看见您写的小书对我帮助很大。感谢
function createStore(s,stateChanger) {
const listeners = []
const queue = []
let state = s
const getState = () => state
let timerId :any = 0
const dispatch = (action) => {
if(typeof action == 'function') {
const d = stateChanger(state,action())
for(const value of listeners) {
value(d)
state = d
}
return;
}
queue.push(() => {
return stateChanger(state,action)
})
clearImmediate(timerId)
timerId = setImmediate (() => {
let d = null
while (queue.length) {
d = queue.shift()()
state = d
}
for(const value of listeners) {
value(d)
}
},1)
}
const subscribe = (listen) => listeners.push(listen)
return { getState,dispatch,subscribe }
}
The text was updated successfully, but these errors were encountered: