@woocommerce/data
Version:
WooCommerce Admin data store and utilities
79 lines (78 loc) • 2.07 kB
JavaScript
/**
* External dependencies
*/
/**
* Internal dependencies
*/
import TYPES from './action-types';
const reducer = (state = {
errors: {},
noteQueries: {},
notes: {},
requesting: {},
}, action) => {
switch (action.type) {
case TYPES.SET_NOTES:
state = {
...state,
notes: {
...state.notes,
...action.notes.reduce((acc, item) => {
acc[item.id] = item;
return acc;
}, {}),
},
};
break;
case TYPES.SET_NOTES_QUERY:
state = {
...state,
noteQueries: {
...state.noteQueries,
[JSON.stringify(action.query)]: action.noteIds,
},
};
break;
case TYPES.SET_ERROR:
state = {
...state,
errors: {
...state.errors,
[action.selector]: action.error,
},
};
break;
case TYPES.SET_NOTE:
state = {
...state,
notes: {
...state.notes,
[action.noteId]: action.noteFields,
},
};
break;
case TYPES.SET_NOTE_IS_UPDATING:
state = {
...state,
notes: {
...state.notes,
[action.noteId]: {
...state.notes[action.noteId],
isUpdating: action.isUpdating,
},
},
};
break;
case TYPES.SET_IS_REQUESTING:
state = {
...state,
requesting: {
...state.requesting,
[action.selector]: action.isRequesting,
},
};
break;
}
return state;
};
export default reducer;