From 2f8ae58f4f5cde892b4b6981a83a37edc1422a2c Mon Sep 17 00:00:00 2001 From: ditoaugusta Date: Tue, 24 Mar 2020 15:04:52 +0700 Subject: experiment: redux toolkit --- modern/src/store/modules/devices.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 modern/src/store/modules/devices.js (limited to 'modern/src/store/modules/devices.js') diff --git a/modern/src/store/modules/devices.js b/modern/src/store/modules/devices.js new file mode 100644 index 0000000..0d96e98 --- /dev/null +++ b/modern/src/store/modules/devices.js @@ -0,0 +1,20 @@ +import { createSlice } from '@reduxjs/toolkit'; + +const { reducer, actions } = createSlice({ + name: 'devices', + initialState: { + items: {}, + selectedId: null + }, + reducers: { + update(state, action) { + action.payload.forEach(item => state.items[item['id']] = item); + }, + select(state, action) { + state.selectedId = action.payload.id; + } + } +}); + +export { actions as devicesActions }; +export { reducer as devicesReducer }; -- cgit v1.2.3