diff --git a/src/actions/ensureSettingsThought.ts b/src/actions/ensureSettingsThought.ts deleted file mode 100644 index 584efcdf474..00000000000 --- a/src/actions/ensureSettingsThought.ts +++ /dev/null @@ -1,18 +0,0 @@ -import State from '../@types/State' -import { EM_TOKEN, SETTINGS_TOKEN, SETTINGS_VALUE } from '../constants' -import findDescendant from '../selectors/findDescendant' -import getPrevRank from '../selectors/getPrevRank' -import createThought from './createThought' - -/** Ensures the fixed /EM/Settings system thought exists before adding concrete setting values below it. */ -const ensureSettingsThought = (state: State): State => - findDescendant(state, EM_TOKEN, SETTINGS_VALUE) - ? state - : createThought(state, { - id: SETTINGS_TOKEN, - path: [EM_TOKEN], - value: SETTINGS_VALUE, - rank: getPrevRank(state, EM_TOKEN), - }) - -export default ensureSettingsThought diff --git a/src/actions/settings.ts b/src/actions/settings.ts index b25f31f0f58..b7d6316df4b 100644 --- a/src/actions/settings.ts +++ b/src/actions/settings.ts @@ -1,10 +1,11 @@ import _ from 'lodash' import State from '../@types/State' import Thunk from '../@types/Thunk' -import { EM_TOKEN, SETTINGS_VALUE } from '../constants' +import { EM_TOKEN, SETTINGS_TOKEN, SETTINGS_VALUE } from '../constants' import findDescendant from '../selectors/findDescendant' +import getPrevRank from '../selectors/getPrevRank' import { registerActionMetadata } from '../util/actionMetadata.registry' -import ensureSettingsThought from './ensureSettingsThought' +import createThought from './createThought' import toggleAttribute from './toggleAttribute' /** Sets a setting thought. */ @@ -13,7 +14,16 @@ const settings = (state: State, { key, value }: { key: string; value: string }) const exists = !!findDescendant(state, EM_TOKEN, emContext) if (exists) return state - return toggleAttribute(ensureSettingsThought(state), { path: [EM_TOKEN], values: emContext }) + const stateWithSettings = findDescendant(state, EM_TOKEN, SETTINGS_VALUE) + ? state + : createThought(state, { + id: SETTINGS_TOKEN, + path: [EM_TOKEN], + value: SETTINGS_VALUE, + rank: getPrevRank(state, EM_TOKEN), + }) + + return toggleAttribute(stateWithSettings, { path: [EM_TOKEN], values: emContext }) } /** Action-creator for settings. */