cra-template-sdw
Version:
The base SDW template for Create React App.
29 lines (25 loc) • 623 B
text/typescript
import { DeleteResponse } from '../requests';
export const createRefresh = (
state: any,
push: boolean = true,
attributes: any
) => {
return push ? state.push(attributes) : state.unshift(attributes);
};
export const updateRefresh = (
state: any,
id: number,
attributes: any
) => {
Object.assign(state[
state.findIndex((model: any) => model.id === id)
], attributes);
};
export const deleteRefresh = (
state: any,
purged: DeleteResponse['data']['attributes']['purged']
) => {
purged?.forEach(({ id }) => {
state.splice(state.findIndex((model: any) => model.id === Number(id)), 1);
});
}