@exodus/ui-config 1.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 +30 -0
- package/api/index.js +31 -0
- package/index.js +33 -0
- package/package.json +35 -0
- package/plugin/index.js +24 -0
- package/utils.js +3 -0
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# @exodus/ui-config
|
|
2
|
+
|
|
3
|
+
Helper for storing various UI-specific settings/config. Use this ONLY for UI-specific settings/config. Most data is NOT UI-specific and should be managed by domain-specific features/modules/atoms in the background.
|
|
4
|
+
|
|
5
|
+
Valid examples:
|
|
6
|
+
|
|
7
|
+
- Boolean flag that controls whether to show price maps in the UI
|
|
8
|
+
- Boolean flag that flips to true after onboarding was shown
|
|
9
|
+
- Counter for how many times a modal has been shown, or needs to be shown
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import uiConfig from '@exodus/ui-config'
|
|
15
|
+
|
|
16
|
+
// exodus is created via `@exodus/headless`
|
|
17
|
+
exodus.use(
|
|
18
|
+
uiConfig({
|
|
19
|
+
atoms: [
|
|
20
|
+
// these are emitted to the `port` as events 'delightUserAtom' and 'terrifyUserAtom'
|
|
21
|
+
{ id: 'delightUserAtom' },
|
|
22
|
+
{ id: 'terrifyUserAtom' },
|
|
23
|
+
],
|
|
24
|
+
})
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
// API usage
|
|
28
|
+
exodus.uiConfig.setDelightUser(true)
|
|
29
|
+
exodus.uiConfig.setTerrifyUser(false)
|
|
30
|
+
```
|
package/api/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { mapValues } from '@exodus/basic-utils'
|
|
2
|
+
import { merge } from 'lodash'
|
|
3
|
+
import { stripAtom, toFirstUpper } from '../utils'
|
|
4
|
+
|
|
5
|
+
const getGetterName = (name) => `get${toFirstUpper(stripAtom(name))}`
|
|
6
|
+
|
|
7
|
+
const getSetterName = (name) => `set${toFirstUpper(stripAtom(name))}`
|
|
8
|
+
|
|
9
|
+
const createUiConfigApiDefinition = ({ atomIds }) => {
|
|
10
|
+
return {
|
|
11
|
+
definition: {
|
|
12
|
+
type: 'api',
|
|
13
|
+
id: 'uiConfig',
|
|
14
|
+
factory: ({ ...atoms }) => ({
|
|
15
|
+
uiConfig: merge(
|
|
16
|
+
...Object.values(
|
|
17
|
+
mapValues(atoms, (atom, name) => ({
|
|
18
|
+
// assetsShowPriceMapAtom -> getAssetsShowPriceMap, setAssetsShowPriceMap
|
|
19
|
+
[getGetterName(name)]: atom.get,
|
|
20
|
+
[getSetterName(name)]: atom.set,
|
|
21
|
+
}))
|
|
22
|
+
)
|
|
23
|
+
),
|
|
24
|
+
}),
|
|
25
|
+
dependencies: atomIds,
|
|
26
|
+
},
|
|
27
|
+
writesAtoms: atomIds,
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default createUiConfigApiDefinition
|
package/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createStorageAtomFactory } from '@exodus/atoms'
|
|
2
|
+
import createUiConfigApiDefinition from './api'
|
|
3
|
+
import createUiConfigPluginDefinition from './plugin'
|
|
4
|
+
import { stripAtom } from './utils'
|
|
5
|
+
|
|
6
|
+
const createUiConfigFeatureDefinition = ({ atoms: uiConfigAtoms }) => {
|
|
7
|
+
const atoms = uiConfigAtoms.map(({ id }) => ({
|
|
8
|
+
definition: {
|
|
9
|
+
id,
|
|
10
|
+
type: 'atom',
|
|
11
|
+
factory: ({ storage, config }) =>
|
|
12
|
+
createStorageAtomFactory({ storage })({
|
|
13
|
+
key: stripAtom(id),
|
|
14
|
+
isSoleWriter: true,
|
|
15
|
+
}),
|
|
16
|
+
dependencies: ['storage'],
|
|
17
|
+
},
|
|
18
|
+
storage: { namespace: 'uiConfig' },
|
|
19
|
+
}))
|
|
20
|
+
|
|
21
|
+
const atomIds = uiConfigAtoms.map(({ id }) => id)
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
id: 'uiConfigFeatureDefinition',
|
|
25
|
+
definitions: [
|
|
26
|
+
...atoms,
|
|
27
|
+
createUiConfigApiDefinition({ atomIds }),
|
|
28
|
+
createUiConfigPluginDefinition({ atomIds }),
|
|
29
|
+
],
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default createUiConfigFeatureDefinition
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@exodus/ui-config",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Helper for storing various UI-specific settings/config.",
|
|
5
|
+
"author": "Exodus Movement Inc.",
|
|
6
|
+
"license": "UNLICENSED",
|
|
7
|
+
"homepage": "https://github.com/ExodusMovement/exodus-hydra/tree/master/features/ui-config",
|
|
8
|
+
"bugs": {
|
|
9
|
+
"url": "https://github.com/ExodusMovement/exodus-hydra/issues?q=is%3Aissue+is%3Aopen+label%3Aui-config"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/ExodusMovement/exodus-hydra.git"
|
|
14
|
+
},
|
|
15
|
+
"main": "index.js",
|
|
16
|
+
"files": [
|
|
17
|
+
"README.md",
|
|
18
|
+
"utils.js",
|
|
19
|
+
"plugin",
|
|
20
|
+
"api"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"lint": "eslint . --ignore-path ../../.gitignore",
|
|
24
|
+
"lint:fix": "yarn lint --fix"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@exodus/atoms": "^5.4.0",
|
|
28
|
+
"@exodus/basic-utils": "^2.1.0",
|
|
29
|
+
"lodash": "^4.17.21"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"eslint": "^8.44.0"
|
|
33
|
+
},
|
|
34
|
+
"gitHead": "14fc30509aaa011e0e214aa6b7e0d6608ad3f7c2"
|
|
35
|
+
}
|
package/plugin/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const createUiConfigPluginDefinition = ({ atomIds }) => ({
|
|
2
|
+
definition: {
|
|
3
|
+
type: 'plugin',
|
|
4
|
+
id: 'uiConfigPlugin',
|
|
5
|
+
factory: ({ port, ...atoms }) => {
|
|
6
|
+
const watch = () =>
|
|
7
|
+
Object.entries(atoms).forEach(([name, atom]) =>
|
|
8
|
+
atom.observe((value) => port.emit(name, value))
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
const clear = () =>
|
|
12
|
+
Promise.all(Object.entries(atoms).map(([name, atom]) => atom.set(undefined)))
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
onStart: watch,
|
|
16
|
+
onClear: clear,
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
dependencies: ['port', ...atomIds],
|
|
20
|
+
},
|
|
21
|
+
writesAtoms: atomIds,
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
export default createUiConfigPluginDefinition
|
package/utils.js
ADDED