@exodus/ui-config 1.0.0 → 2.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 +12 -8
- package/package.json +2 -2
- package/plugin/index.js +3 -3
- package/utils.js +0 -3
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,20 @@
|
|
|
1
1
|
import { createStorageAtomFactory } from '@exodus/atoms'
|
|
2
2
|
import createUiConfigApiDefinition from './api'
|
|
3
3
|
import createUiConfigPluginDefinition from './plugin'
|
|
4
|
-
import { stripAtom } from './utils'
|
|
5
4
|
|
|
6
|
-
const createUiConfigFeatureDefinition = ({
|
|
7
|
-
const
|
|
5
|
+
const createUiConfigFeatureDefinition = ({ config }) => {
|
|
6
|
+
const getAtomId = (id) => `${id}Atom`
|
|
7
|
+
const configAtomMap = Object.fromEntries(config.map(({ id }) => [id, getAtomId(id)]))
|
|
8
|
+
const atomConfigMap = Object.fromEntries(
|
|
9
|
+
Object.keys(configAtomMap).map((configId) => [configAtomMap[configId], configId])
|
|
10
|
+
)
|
|
11
|
+
const atoms = config.map(({ id }) => ({
|
|
8
12
|
definition: {
|
|
9
|
-
id,
|
|
13
|
+
id: configAtomMap[id],
|
|
10
14
|
type: 'atom',
|
|
11
15
|
factory: ({ storage, config }) =>
|
|
12
16
|
createStorageAtomFactory({ storage })({
|
|
13
|
-
key:
|
|
17
|
+
key: id,
|
|
14
18
|
isSoleWriter: true,
|
|
15
19
|
}),
|
|
16
20
|
dependencies: ['storage'],
|
|
@@ -18,14 +22,14 @@ const createUiConfigFeatureDefinition = ({ atoms: uiConfigAtoms }) => {
|
|
|
18
22
|
storage: { namespace: 'uiConfig' },
|
|
19
23
|
}))
|
|
20
24
|
|
|
21
|
-
const atomIds =
|
|
25
|
+
const atomIds = Object.keys(atomConfigMap)
|
|
22
26
|
|
|
23
27
|
return {
|
|
24
28
|
id: 'uiConfigFeatureDefinition',
|
|
25
29
|
definitions: [
|
|
26
30
|
...atoms,
|
|
27
|
-
createUiConfigApiDefinition({ atomIds }),
|
|
28
|
-
createUiConfigPluginDefinition({ atomIds }),
|
|
31
|
+
createUiConfigApiDefinition({ atomIds, atomConfigMap }),
|
|
32
|
+
createUiConfigPluginDefinition({ atomIds, atomConfigMap }),
|
|
29
33
|
],
|
|
30
34
|
}
|
|
31
35
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/ui-config",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Helper for storing various UI-specific settings/config.",
|
|
5
5
|
"author": "Exodus Movement Inc.",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"eslint": "^8.44.0"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "77f9575942b25e8cd2229c79889264c5994b7bb6"
|
|
35
35
|
}
|
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
DELETED