Skip to content
javascript
function reducer(state = { count: 0 }, action) {
    switch (action.type) {
        case 'add':
            return { count: (state.count += 1) }
            break
        default:
            return state
            break
    }
}
// 生成 store 实例
const store = Redux.createStore(reducer)

// 触发增函数
store.dispath({ action: 'add' })

// 订阅变化
store.subscribe(() => {
    console.log('changed', store.getState())
})

img_1.pngimg_2.pngimg_3.pngimg_4.pngimg_5.png