more cleanup

This commit is contained in:
Martin McKeaveney 2020-03-22 13:10:55 +00:00
parent a473858110
commit f32945958f
1 changed files with 4 additions and 11 deletions

View File

@ -1,16 +1,13 @@
import { writable } from "svelte/store"; import { writable } from "svelte/store";
import api from "../api" import api from "../api"
import { import {
filter,
cloneDeep, cloneDeep,
sortBy, sortBy,
map,
find, find,
remove remove
} from "lodash/fp" } from "lodash/fp"
import { hierarchy as hierarchyFunctions } from "../../../../core/src" import { hierarchy as hierarchyFunctions } from "../../../../core/src"
import { import {
pipe,
getNode, getNode,
validate, validate,
constructHierarchy, constructHierarchy,
@ -228,9 +225,7 @@ export const saveLevel = store => (newLevel, isNew, oldLevel = null) => {
export const deleteLevel = store => level => { export const deleteLevel = store => level => {
store.update(state => { store.update(state => {
state.accessLevelstate.levels = filter(t => t.name !== level.name)( state.accessLevels.levels = state.accessLevels.levels.filter(t => t.name !== level.name)
state.accessLevelstate.levels
)
incrementAccessLevelsVersion(s) incrementAccessLevelsVersion(s)
saveBackend(state) saveBackend(state)
return state return state
@ -265,12 +260,10 @@ export const saveTrigger = store => (newTrigger, isNew, oldTrigger = null) => {
store.update(s => { store.update(s => {
const existingTrigger = isNew const existingTrigger = isNew
? null ? null
: find(a => a.name === oldTrigger.name)(s.triggers) : s.triggers.find(a => a.name === oldTrigger.name)
if (existingTrigger) { if (existingTrigger) {
s.triggers = pipe(s.triggers, [ s.triggers = s.triggers.map(a => (a === existingTrigger ? newTrigger : a))
map(a => (a === existingTrigger ? newTrigger : a)),
])
} else { } else {
s.triggers.push(newTrigger) s.triggers.push(newTrigger)
} }
@ -281,7 +274,7 @@ export const saveTrigger = store => (newTrigger, isNew, oldTrigger = null) => {
export const deleteTrigger = store => trigger => { export const deleteTrigger = store => trigger => {
store.update(s => { store.update(s => {
s.triggers = filter(t => t.name !== trigger.name)(s.triggers) s.triggers = s.triggers.filter(t => t.name !== trigger.name)
return s return s
}) })
} }