source: node_modules/recharts/es6/state/graphicalItemsSlice.js@ a762898

Last change on this file since a762898 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 2.0 KB
Line 
1import { createSlice, current, prepareAutoBatched } from '@reduxjs/toolkit';
2import { castDraft } from 'immer';
3
4/**
5 * Unique ID of the graphical item.
6 * This is used to identify the graphical item in the state and in the React tree.
7 * This is required for every graphical item - it's either provided by the user or generated automatically.
8 */
9
10var initialState = {
11 cartesianItems: [],
12 polarItems: []
13};
14var graphicalItemsSlice = createSlice({
15 name: 'graphicalItems',
16 initialState,
17 reducers: {
18 addCartesianGraphicalItem: {
19 reducer(state, action) {
20 state.cartesianItems.push(castDraft(action.payload));
21 },
22 prepare: prepareAutoBatched()
23 },
24 replaceCartesianGraphicalItem: {
25 reducer(state, action) {
26 var {
27 prev,
28 next
29 } = action.payload;
30 var index = current(state).cartesianItems.indexOf(castDraft(prev));
31 if (index > -1) {
32 state.cartesianItems[index] = castDraft(next);
33 }
34 },
35 prepare: prepareAutoBatched()
36 },
37 removeCartesianGraphicalItem: {
38 reducer(state, action) {
39 var index = current(state).cartesianItems.indexOf(castDraft(action.payload));
40 if (index > -1) {
41 state.cartesianItems.splice(index, 1);
42 }
43 },
44 prepare: prepareAutoBatched()
45 },
46 addPolarGraphicalItem: {
47 reducer(state, action) {
48 state.polarItems.push(castDraft(action.payload));
49 },
50 prepare: prepareAutoBatched()
51 },
52 removePolarGraphicalItem: {
53 reducer(state, action) {
54 var index = current(state).polarItems.indexOf(castDraft(action.payload));
55 if (index > -1) {
56 state.polarItems.splice(index, 1);
57 }
58 },
59 prepare: prepareAutoBatched()
60 }
61 }
62});
63export var {
64 addCartesianGraphicalItem,
65 replaceCartesianGraphicalItem,
66 removeCartesianGraphicalItem,
67 addPolarGraphicalItem,
68 removePolarGraphicalItem
69} = graphicalItemsSlice.actions;
70export var graphicalItemsReducer = graphicalItemsSlice.reducer;
Note: See TracBrowser for help on using the repository browser.