@razorpay/blade
Version:
The Design System that powers Razorpay
75 lines (71 loc) • 2.39 kB
JavaScript
import { createSlice, prepareAutoBatched } from '../../../@reduxjs/toolkit/dist/redux-toolkit.modern.js';
import { castDraft } from '../../../immer/dist/immer.js';
import { current } from '../../../@reduxjs/toolkit/node_modules/immer/dist/immer.js';
/**
* Unique ID of the graphical item.
* This is used to identify the graphical item in the state and in the React tree.
* This is required for every graphical item - it's either provided by the user or generated automatically.
*/
var initialState = {
cartesianItems: [],
polarItems: []
};
var graphicalItemsSlice = createSlice({
name: 'graphicalItems',
initialState,
reducers: {
addCartesianGraphicalItem: {
reducer(state, action) {
state.cartesianItems.push(castDraft(action.payload));
},
prepare: prepareAutoBatched()
},
replaceCartesianGraphicalItem: {
reducer(state, action) {
var {
prev,
next
} = action.payload;
var index = current(state).cartesianItems.indexOf(castDraft(prev));
if (index > -1) {
state.cartesianItems[index] = castDraft(next);
}
},
prepare: prepareAutoBatched()
},
removeCartesianGraphicalItem: {
reducer(state, action) {
var index = current(state).cartesianItems.indexOf(castDraft(action.payload));
if (index > -1) {
state.cartesianItems.splice(index, 1);
}
},
prepare: prepareAutoBatched()
},
addPolarGraphicalItem: {
reducer(state, action) {
state.polarItems.push(castDraft(action.payload));
},
prepare: prepareAutoBatched()
},
removePolarGraphicalItem: {
reducer(state, action) {
var index = current(state).polarItems.indexOf(castDraft(action.payload));
if (index > -1) {
state.polarItems.splice(index, 1);
}
},
prepare: prepareAutoBatched()
}
}
});
var {
addCartesianGraphicalItem,
replaceCartesianGraphicalItem,
removeCartesianGraphicalItem,
addPolarGraphicalItem,
removePolarGraphicalItem
} = graphicalItemsSlice.actions;
var graphicalItemsReducer = graphicalItemsSlice.reducer;
export { addCartesianGraphicalItem, addPolarGraphicalItem, graphicalItemsReducer, removeCartesianGraphicalItem, removePolarGraphicalItem, replaceCartesianGraphicalItem };
//# sourceMappingURL=graphicalItemsSlice.js.map