合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
~~~ import {createStore} from './redux'; let counterValEle = document.getElementById('counterVal'); let addBtn = document.getElementById('addBtn'); let minusBtn = document.getElementById('minusBtn'); function reducer(state={number:0},action){ switch(action.type){ case 'ADD': return {number:state.number+1}; case 'MINUS': return {number:state.number-1}; default: return state; } } let store = createStore(reducer); function render(){ counterValEle.innerHTML = store.getState().number; } render(); store.subscribe(render); addBtn.addEventListener('click',()=>store.dispatch({type:'ADD'})); minusBtn.addEventListener('click',()=>store.dispatch({type:'MINUS'})); ~~~