reducer.js
48 lines
| 1 | const { combineReducers } = wp.data; |
| 2 | |
| 3 | const settingsReducer = (state = {}, action) => { |
| 4 | switch (action.type) { |
| 5 | case "SET_SETTINGS": |
| 6 | return action.settings; |
| 7 | |
| 8 | case "UPDATE_SETTING": |
| 9 | return { |
| 10 | ...state, |
| 11 | [`presto_player_${action.optionName}`]: { |
| 12 | ...state[`presto_player_${action.optionName}`], |
| 13 | [action.name]: action.value, |
| 14 | }, |
| 15 | }; |
| 16 | } |
| 17 | return state; |
| 18 | }; |
| 19 | |
| 20 | const uiReducer = (state = { notices: [], saving: false }, action) => { |
| 21 | switch (action.type) { |
| 22 | case "SET_SAVING": |
| 23 | return { |
| 24 | ...state, |
| 25 | saving: action.value, |
| 26 | }; |
| 27 | case "SET_NOTICE": |
| 28 | return { |
| 29 | ...state, |
| 30 | notices: [ |
| 31 | ...state.notices, |
| 32 | { id: state.notices.length, ...action.notice }, |
| 33 | ], |
| 34 | }; |
| 35 | case "REMOVE_NOTICE": |
| 36 | return { |
| 37 | ...state, |
| 38 | notices: state.notices.filter((notice) => notice.id !== action.id), |
| 39 | }; |
| 40 | } |
| 41 | return state; |
| 42 | }; |
| 43 | |
| 44 | export default combineReducers({ |
| 45 | settingsReducer, |
| 46 | uiReducer, |
| 47 | }); |
| 48 |