TS
SET_CURRENT_EDITOR_CODE:
return {...state, code: state.code.concat([action.payload])}
? а то он может положить при клике одни и те же значенияSize: a a a
TS
ДИ
SET_CURRENT_EDITOR_CODE:
return {...state, code: state.code.concat([action.payload])}
? а то он может положить при клике одни и те же значенияAG
AG
j
dr
AG
j
j
AG
TS
j
const cache = {}
items.forEach(item => {
if (!cache[item.id] || (item.opened && !cache[item.id].opened)) {
cache[item.id] = item
}
})
console.log(Object.values(cache))
AG
const cache = {}
items.forEach(item => {
if (!cache[item.id] || (item.opened && !cache[item.id].opened)) {
cache[item.id] = item
}
})
console.log(Object.values(cache))
AG
const cache = {}
items.forEach(item => {
if (!cache[item.id] || (item.opened && !cache[item.id].opened)) {
cache[item.id] = item
}
})
console.log(Object.values(cache))
М
SET_CURRENT_EDITOR_CODE:
return {...state, code: state.code.concat([action.payload])}
? а то он может положить при клике одни и те же значенияДИ
М
ДИ
import {DELETE_CURRENT_EDITOR_CODE, SET_CURRENT_EDITOR_CODE} from './actions';
const initialState = {
code: []
};
export const codeReducer = (state = initialState, action) => {
switch (action.type) {
case SET_CURRENT_EDITOR_CODE:
return {...state, code: state.code.concat([action.payload])}
case DELETE_CURRENT_EDITOR_CODE:
return {...state, code: state.code.filter(i => i.index !== action.payload)}
default:
return state
}
}
ДИ
М
import {DELETE_CURRENT_EDITOR_CODE, SET_CURRENT_EDITOR_CODE} from './actions';
const initialState = {
code: []
};
export const codeReducer = (state = initialState, action) => {
switch (action.type) {
case SET_CURRENT_EDITOR_CODE:
return {...state, code: state.code.concat([action.payload])}
case DELETE_CURRENT_EDITOR_CODE:
return {...state, code: state.code.filter(i => i.index !== action.payload)}
default:
return state
}
}
if (!state.code.includes(action.payload)) {
return {...state, code: state.code.concat([action.payload])}
}