@exodus/atoms 2.5.0 → 2.5.1
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/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/atoms",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.1",
|
|
4
4
|
"main": "src/index.js",
|
|
5
5
|
"author": "Exodus Movement Inc.",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "jest",
|
|
8
|
-
"lint": "eslint .",
|
|
8
|
+
"lint": "eslint . --ignore-path ../../.gitignore",
|
|
9
9
|
"lint:fix": "yarn lint --fix"
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"delay": "^5.0.0",
|
|
31
31
|
"jest": "^29.1.2"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "791cafc56909b0eb584a1e6526dc2cbd3f6fd235"
|
|
34
34
|
}
|
package/src/factories/storage.js
CHANGED
|
@@ -6,18 +6,33 @@ const createStorageAtomFactory =
|
|
|
6
6
|
({ key, defaultValue, isSoleWriter }) => {
|
|
7
7
|
const { notify, observe } = createSimpleObserver({ enable: isSoleWriter })
|
|
8
8
|
|
|
9
|
+
let cached
|
|
9
10
|
const set = async (value) => {
|
|
10
11
|
if (typeof value === 'undefined') {
|
|
11
12
|
await storage.delete(key)
|
|
12
13
|
} else {
|
|
13
14
|
await storage.set(key, value)
|
|
14
15
|
}
|
|
16
|
+
|
|
15
17
|
if (isSoleWriter) {
|
|
18
|
+
cached = value
|
|
16
19
|
await notify(value)
|
|
17
20
|
}
|
|
18
21
|
}
|
|
19
22
|
|
|
20
|
-
const get = () =>
|
|
23
|
+
const get = async () => {
|
|
24
|
+
if (cached) {
|
|
25
|
+
return cached
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const value = await storage.get(key)
|
|
29
|
+
|
|
30
|
+
if (isSoleWriter) {
|
|
31
|
+
cached = value
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return value
|
|
35
|
+
}
|
|
21
36
|
|
|
22
37
|
return enforceObservableRules({
|
|
23
38
|
get,
|