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
function createStore(reducer, state = null){ let listeners = []; let getState = () => state; let subscribe = listener => listeners.push(listener); let dispatch = (action) => { state = reducer(state, action); listeners.forEach(listener => listener()); } return { getState, subscribe, dispatch } } const initialState = { couter: 0 } function reduers(state, action){ if(!state){ return initialState } switch(action.type){ case 'ADD': let num = state.couter num += action.num; return { ...state, couter: num } } } const store = createStore(reduers, initialState) store.subscribe(()=>{ console.log(`当前state,${JSON.stringify(store.getState())}`) }) store.dispatch({ type: 'ADD', num: 1 }) store.dispatch({ type: 'ADD', num: 1 }) store.dispatch({ type: 'ADD', num: 1 })
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The text was updated successfully, but these errors were encountered: