@exodus/ui-config 1.0.0 → 3.0.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/README.md +12 -6
- package/api/index.js +13 -13
- package/index.js +16 -8
- package/package.json +10 -6
- package/plugin/index.js +3 -3
- package/utils.js +13 -2
package/README.md
CHANGED
|
@@ -16,15 +16,21 @@ import uiConfig from '@exodus/ui-config'
|
|
|
16
16
|
// exodus is created via `@exodus/headless`
|
|
17
17
|
exodus.use(
|
|
18
18
|
uiConfig({
|
|
19
|
-
|
|
20
|
-
// these are
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
config: [
|
|
20
|
+
// Note: these are NOT atom definitions, they're only metadata about atoms: `id` and later `type` (so we can
|
|
21
|
+
// internally instantiate different types of atoms)
|
|
22
|
+
//
|
|
23
|
+
// these are emitted to the `port` as events 'delightUser' and 'terrifyUser'
|
|
24
|
+
{ id: 'delightUser' },
|
|
25
|
+
{ id: 'terrifyUser' },
|
|
23
26
|
],
|
|
24
27
|
})
|
|
25
28
|
)
|
|
26
29
|
|
|
27
30
|
// API usage
|
|
28
|
-
exodus.uiConfig.
|
|
29
|
-
exodus.uiConfig.
|
|
31
|
+
exodus.uiConfig.delightUser(true)
|
|
32
|
+
exodus.uiConfig.terrifyUser(false)
|
|
30
33
|
```
|
|
34
|
+
|
|
35
|
+
// Port events
|
|
36
|
+
feature emit data from atoms in with following format: `port.emit('delightUserAtom', value)`
|
package/api/index.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import { mapValues } from '@exodus/basic-utils'
|
|
2
2
|
import { merge } from 'lodash'
|
|
3
|
-
import { stripAtom, toFirstUpper } from '../utils'
|
|
4
3
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const getSetterName = (name) => `set${toFirstUpper(stripAtom(name))}`
|
|
8
|
-
|
|
9
|
-
const createUiConfigApiDefinition = ({ atomIds }) => {
|
|
4
|
+
const createUiConfigApiDefinition = ({ atomIds, atomConfigMap }) => {
|
|
10
5
|
return {
|
|
11
6
|
definition: {
|
|
12
7
|
type: 'api',
|
|
13
8
|
id: 'uiConfig',
|
|
14
|
-
factory: ({ ...atoms }) =>
|
|
15
|
-
uiConfig
|
|
9
|
+
factory: ({ ...atoms }) => {
|
|
10
|
+
const uiConfig = merge(
|
|
16
11
|
...Object.values(
|
|
17
|
-
mapValues(atoms, (atom,
|
|
12
|
+
mapValues(atoms, (atom, atomId) => ({
|
|
18
13
|
// assetsShowPriceMapAtom -> getAssetsShowPriceMap, setAssetsShowPriceMap
|
|
19
|
-
[
|
|
20
|
-
|
|
14
|
+
[atomConfigMap[atomId]]: {
|
|
15
|
+
set: atom.set,
|
|
16
|
+
get: atom.get,
|
|
17
|
+
},
|
|
21
18
|
}))
|
|
22
19
|
)
|
|
23
|
-
)
|
|
24
|
-
|
|
20
|
+
)
|
|
21
|
+
return {
|
|
22
|
+
uiConfig,
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
25
|
dependencies: atomIds,
|
|
26
26
|
},
|
|
27
27
|
writesAtoms: atomIds,
|
package/index.js
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import { createStorageAtomFactory } from '@exodus/atoms'
|
|
2
|
+
|
|
2
3
|
import createUiConfigApiDefinition from './api'
|
|
3
4
|
import createUiConfigPluginDefinition from './plugin'
|
|
4
|
-
import {
|
|
5
|
+
import { getAtomId } from './utils'
|
|
6
|
+
|
|
7
|
+
export { getConfigReduxEvents, getEventReduxMap } from './utils'
|
|
5
8
|
|
|
6
|
-
const createUiConfigFeatureDefinition = ({
|
|
7
|
-
const
|
|
9
|
+
const createUiConfigFeatureDefinition = ({ config }) => {
|
|
10
|
+
const configValues = Object.values(config)
|
|
11
|
+
const configAtomMap = Object.fromEntries(configValues.map(({ id }) => [id, getAtomId(id)]))
|
|
12
|
+
const atomConfigMap = Object.fromEntries(
|
|
13
|
+
Object.keys(configAtomMap).map((configId) => [configAtomMap[configId], configId])
|
|
14
|
+
)
|
|
15
|
+
const atoms = configValues.map(({ id }) => ({
|
|
8
16
|
definition: {
|
|
9
|
-
id,
|
|
17
|
+
id: configAtomMap[id],
|
|
10
18
|
type: 'atom',
|
|
11
19
|
factory: ({ storage, config }) =>
|
|
12
20
|
createStorageAtomFactory({ storage })({
|
|
13
|
-
key:
|
|
21
|
+
key: id,
|
|
14
22
|
isSoleWriter: true,
|
|
15
23
|
}),
|
|
16
24
|
dependencies: ['storage'],
|
|
@@ -18,14 +26,14 @@ const createUiConfigFeatureDefinition = ({ atoms: uiConfigAtoms }) => {
|
|
|
18
26
|
storage: { namespace: 'uiConfig' },
|
|
19
27
|
}))
|
|
20
28
|
|
|
21
|
-
const atomIds =
|
|
29
|
+
const atomIds = Object.keys(atomConfigMap)
|
|
22
30
|
|
|
23
31
|
return {
|
|
24
32
|
id: 'uiConfigFeatureDefinition',
|
|
25
33
|
definitions: [
|
|
26
34
|
...atoms,
|
|
27
|
-
createUiConfigApiDefinition({ atomIds }),
|
|
28
|
-
createUiConfigPluginDefinition({ atomIds }),
|
|
35
|
+
createUiConfigApiDefinition({ atomIds, atomConfigMap }),
|
|
36
|
+
createUiConfigPluginDefinition({ atomIds, atomConfigMap }),
|
|
29
37
|
],
|
|
30
38
|
}
|
|
31
39
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/ui-config",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.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,23 @@
|
|
|
17
17
|
"README.md",
|
|
18
18
|
"utils.js",
|
|
19
19
|
"plugin",
|
|
20
|
-
"api"
|
|
20
|
+
"api",
|
|
21
|
+
"utils"
|
|
21
22
|
],
|
|
22
23
|
"scripts": {
|
|
23
24
|
"lint": "eslint . --ignore-path ../../.gitignore",
|
|
24
|
-
"lint:fix": "yarn lint --fix"
|
|
25
|
+
"lint:fix": "yarn lint --fix",
|
|
26
|
+
"test": "jest"
|
|
25
27
|
},
|
|
26
28
|
"dependencies": {
|
|
27
|
-
"@exodus/atoms": "^5.
|
|
29
|
+
"@exodus/atoms": "^5.6.0",
|
|
28
30
|
"@exodus/basic-utils": "^2.1.0",
|
|
31
|
+
"@exodus/formatting": "^1.1.1",
|
|
29
32
|
"lodash": "^4.17.21"
|
|
30
33
|
},
|
|
31
34
|
"devDependencies": {
|
|
32
|
-
"eslint": "^8.44.0"
|
|
35
|
+
"eslint": "^8.44.0",
|
|
36
|
+
"jest": "^29.1.2"
|
|
33
37
|
},
|
|
34
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "0840a06d2b117adb4895d978418394cdf5a1a128"
|
|
35
39
|
}
|
package/plugin/index.js
CHANGED
|
@@ -4,9 +4,9 @@ const createUiConfigPluginDefinition = ({ atomIds }) => ({
|
|
|
4
4
|
id: 'uiConfigPlugin',
|
|
5
5
|
factory: ({ port, ...atoms }) => {
|
|
6
6
|
const watch = () =>
|
|
7
|
-
Object.entries(atoms).forEach(([
|
|
8
|
-
atom.observe((value) => port.emit(
|
|
9
|
-
)
|
|
7
|
+
Object.entries(atoms).forEach(([atomId, atom]) => {
|
|
8
|
+
return atom.observe((value) => port.emit(atomId, value))
|
|
9
|
+
})
|
|
10
10
|
|
|
11
11
|
const clear = () =>
|
|
12
12
|
Promise.all(Object.entries(atoms).map(([name, atom]) => atom.set(undefined)))
|
package/utils.js
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import { toUpperSnakeCase } from '@exodus/formatting'
|
|
2
2
|
|
|
3
|
-
export const
|
|
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]))
|