@exodus/ui-config 2.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -1,14 +1,18 @@
1
1
  import { createStorageAtomFactory } from '@exodus/atoms'
2
+
2
3
  import createUiConfigApiDefinition from './api'
3
4
  import createUiConfigPluginDefinition from './plugin'
5
+ import { getAtomId } from './utils'
6
+
7
+ export { getConfigReduxEvents, getEventReduxMap } from './utils'
4
8
 
5
9
  const createUiConfigFeatureDefinition = ({ config }) => {
6
- const getAtomId = (id) => `${id}Atom`
7
- const configAtomMap = Object.fromEntries(config.map(({ id }) => [id, getAtomId(id)]))
10
+ const configValues = Object.values(config)
11
+ const configAtomMap = Object.fromEntries(configValues.map(({ id }) => [id, getAtomId(id)]))
8
12
  const atomConfigMap = Object.fromEntries(
9
13
  Object.keys(configAtomMap).map((configId) => [configAtomMap[configId], configId])
10
14
  )
11
- const atoms = config.map(({ id }) => ({
15
+ const atoms = configValues.map(({ id }) => ({
12
16
  definition: {
13
17
  id: configAtomMap[id],
14
18
  type: 'atom',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/ui-config",
3
- "version": "2.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Helper for storing various UI-specific settings/config.",
5
5
  "author": "Exodus Movement Inc.",
6
6
  "license": "UNLICENSED",
@@ -17,19 +17,27 @@
17
17
  "README.md",
18
18
  "utils.js",
19
19
  "plugin",
20
- "api"
20
+ "api",
21
+ "utils",
22
+ "redux",
23
+ "!**/__tests__/**"
21
24
  ],
22
25
  "scripts": {
23
26
  "lint": "eslint . --ignore-path ../../.gitignore",
24
- "lint:fix": "yarn lint --fix"
27
+ "lint:fix": "yarn lint --fix",
28
+ "test": "jest"
25
29
  },
26
30
  "dependencies": {
27
- "@exodus/atoms": "^5.4.0",
31
+ "@exodus/atoms": "^5.6.0",
28
32
  "@exodus/basic-utils": "^2.1.0",
33
+ "@exodus/formatting": "^1.1.1",
29
34
  "lodash": "^4.17.21"
30
35
  },
31
36
  "devDependencies": {
32
- "eslint": "^8.44.0"
37
+ "@exodus/redux-dependency-injection": "^3.0.0",
38
+ "eslint": "^8.44.0",
39
+ "jest": "^29.1.2",
40
+ "redux": "^4.2.1"
33
41
  },
34
- "gitHead": "77f9575942b25e8cd2229c79889264c5994b7bb6"
42
+ "gitHead": "6971e131f985a06823cca580d424122f53e7f93a"
35
43
  }
package/redux/id.js ADDED
@@ -0,0 +1 @@
1
+ export default 'uiConfig'
package/redux/index.js ADDED
@@ -0,0 +1,26 @@
1
+ import id from './id'
2
+ import { getAtomId } from '../utils'
3
+
4
+ const createUiConfigReduxDefinition = (config) => {
5
+ const configValues = Object.values(config)
6
+ const configAtomMap = configValues.map(({ id }) => [id, getAtomId(id)])
7
+ const initialState = Object.fromEntries(configValues.map(({ id }) => [id, undefined]))
8
+ const eventReducers = Object.fromEntries(
9
+ configAtomMap.map(([configId, atomId]) => [
10
+ atomId,
11
+ (state, payload) => {
12
+ return { ...state, [configId]: payload }
13
+ },
14
+ ])
15
+ )
16
+
17
+ return {
18
+ id,
19
+ type: 'redux-module',
20
+ initialState,
21
+ eventReducers,
22
+ selectorDefinitions: [],
23
+ }
24
+ }
25
+
26
+ export default createUiConfigReduxDefinition
package/utils.js ADDED
@@ -0,0 +1,14 @@
1
+ import { toUpperSnakeCase } from '@exodus/formatting'
2
+
3
+ export const getAtomId = (id) => `${id}ConfigAtom`
4
+
5
+ const toReduxEvent = (type) => `EVENT_${toUpperSnakeCase(type.replace(/configatom$/i, ''))}_CONFIG`
6
+ const getConfigReduxEventName = (id) => toReduxEvent(getAtomId(id))
7
+
8
+ export const getEventReduxMap = (config) =>
9
+ Object.fromEntries(
10
+ Object.values(config).map(({ id }) => [getAtomId(id), getConfigReduxEventName(id)])
11
+ )
12
+
13
+ export const getConfigReduxEvents = (config) =>
14
+ new Map(Object.values(config).map(({ id }) => [getConfigReduxEventName(id), id]))