| 1 | import { createSlice, current } from '@reduxjs/toolkit';
|
|---|
| 2 | import { castDraft } from 'immer';
|
|---|
| 3 | var initialState = {
|
|---|
| 4 | dots: [],
|
|---|
| 5 | areas: [],
|
|---|
| 6 | lines: []
|
|---|
| 7 | };
|
|---|
| 8 | export var referenceElementsSlice = createSlice({
|
|---|
| 9 | name: 'referenceElements',
|
|---|
| 10 | initialState,
|
|---|
| 11 | reducers: {
|
|---|
| 12 | addDot: (state, action) => {
|
|---|
| 13 | state.dots.push(action.payload);
|
|---|
| 14 | },
|
|---|
| 15 | removeDot: (state, action) => {
|
|---|
| 16 | var index = current(state).dots.findIndex(dot => dot === action.payload);
|
|---|
| 17 | if (index !== -1) {
|
|---|
| 18 | state.dots.splice(index, 1);
|
|---|
| 19 | }
|
|---|
| 20 | },
|
|---|
| 21 | addArea: (state, action) => {
|
|---|
| 22 | state.areas.push(action.payload);
|
|---|
| 23 | },
|
|---|
| 24 | removeArea: (state, action) => {
|
|---|
| 25 | var index = current(state).areas.findIndex(area => area === action.payload);
|
|---|
| 26 | if (index !== -1) {
|
|---|
| 27 | state.areas.splice(index, 1);
|
|---|
| 28 | }
|
|---|
| 29 | },
|
|---|
| 30 | addLine: (state, action) => {
|
|---|
| 31 | state.lines.push(castDraft(action.payload));
|
|---|
| 32 | },
|
|---|
| 33 | removeLine: (state, action) => {
|
|---|
| 34 | var index = current(state).lines.findIndex(line => line === action.payload);
|
|---|
| 35 | if (index !== -1) {
|
|---|
| 36 | state.lines.splice(index, 1);
|
|---|
| 37 | }
|
|---|
| 38 | }
|
|---|
| 39 | }
|
|---|
| 40 | });
|
|---|
| 41 | export var {
|
|---|
| 42 | addDot,
|
|---|
| 43 | removeDot,
|
|---|
| 44 | addArea,
|
|---|
| 45 | removeArea,
|
|---|
| 46 | addLine,
|
|---|
| 47 | removeLine
|
|---|
| 48 | } = referenceElementsSlice.actions;
|
|---|
| 49 | export var referenceElementsReducer = referenceElementsSlice.reducer; |
|---|