@yaasl/core 0.10.1 → 0.10.2
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/dist/@types/effects/expiration.d.ts +1 -1
- package/dist/@types/effects/migration.d.ts +1 -1
- package/dist/cjs/base/createAtom.js +4 -1
- package/dist/cjs/base/createDerived.js +7 -4
- package/dist/cjs/effects/indexedDb.js +3 -3
- package/dist/mjs/base/createAtom.js +4 -1
- package/dist/mjs/base/createDerived.js +5 -2
- package/package.json +2 -2
|
@@ -14,4 +14,4 @@ export interface ExpirationOptions {
|
|
|
14
14
|
*
|
|
15
15
|
* @returns The effect to be used on atoms.
|
|
16
16
|
**/
|
|
17
|
-
export declare const expiration: (
|
|
17
|
+
export declare const expiration: (optionsArg: ExpirationOptions) => import("./createEffect").EffectAtomCallback<ExpirationOptions, any>;
|
|
@@ -25,7 +25,7 @@ export interface MigrationOptions {
|
|
|
25
25
|
*
|
|
26
26
|
* @returns The effect to be used on atoms.
|
|
27
27
|
**/
|
|
28
|
-
export declare const migration: (
|
|
28
|
+
export declare const migration: (optionsArg: MigrationOptions) => import("./createEffect").EffectAtomCallback<MigrationOptions, unknown>;
|
|
29
29
|
/** Helper to create a step for the migration effect.
|
|
30
30
|
*
|
|
31
31
|
* @param migration Migration step to create.
|
|
@@ -45,7 +45,10 @@ class Atom extends Stateful_1.Stateful {
|
|
|
45
45
|
* new value based off the previous value.
|
|
46
46
|
*/
|
|
47
47
|
set(next) {
|
|
48
|
-
const
|
|
48
|
+
const oldState = this.get();
|
|
49
|
+
const newState = (0, utils_1.updater)(next, oldState);
|
|
50
|
+
if (oldState === newState)
|
|
51
|
+
return;
|
|
49
52
|
void this.effects
|
|
50
53
|
.dispatch("set", newState)
|
|
51
54
|
.then(value => super.update(value));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.SettableDerive = exports.Derive = void 0;
|
|
4
|
+
exports.createDerived = createDerived;
|
|
4
5
|
const utils_1 = require("@yaasl/utils");
|
|
5
6
|
const Stateful_1 = require("./Stateful");
|
|
6
7
|
const allDidInit = (atoms) => {
|
|
@@ -50,9 +51,12 @@ class SettableDerive extends Derive {
|
|
|
50
51
|
* new value based off the previous value.
|
|
51
52
|
*/
|
|
52
53
|
set(next) {
|
|
53
|
-
const
|
|
54
|
+
const oldState = this.get();
|
|
55
|
+
const newState = (0, utils_1.updater)(next, oldState);
|
|
56
|
+
if (oldState === newState)
|
|
57
|
+
return;
|
|
54
58
|
this.setter({
|
|
55
|
-
value,
|
|
59
|
+
value: newState,
|
|
56
60
|
set: (atom, next) => {
|
|
57
61
|
const value = (0, utils_1.updater)(next, atom.get());
|
|
58
62
|
atom.set(value);
|
|
@@ -81,4 +85,3 @@ function createDerived(getter, setter) {
|
|
|
81
85
|
return new Derive(getter);
|
|
82
86
|
}
|
|
83
87
|
}
|
|
84
|
-
exports.createDerived = createDerived;
|
|
@@ -28,10 +28,10 @@ exports.indexedDb = (0, createEffect_1.createEffect)(({ atom, options }) => {
|
|
|
28
28
|
var _a;
|
|
29
29
|
const key = (_a = options === null || options === void 0 ? void 0 : options.key) !== null && _a !== void 0 ? _a : atom.name;
|
|
30
30
|
return {
|
|
31
|
-
init: (
|
|
32
|
-
var
|
|
31
|
+
init: (_a) => __awaiter(void 0, [_a], void 0, function* ({ atom, set }) {
|
|
32
|
+
var _b;
|
|
33
33
|
if (!atomDb) {
|
|
34
|
-
atomDb = new Store_1.Store((
|
|
34
|
+
atomDb = new Store_1.Store((_b = base_1.CONFIG.name) !== null && _b !== void 0 ? _b : "yaasl");
|
|
35
35
|
}
|
|
36
36
|
const existing = yield atomDb.get(key);
|
|
37
37
|
if (existing != null) {
|
|
@@ -47,7 +47,10 @@ export class Atom extends Stateful {
|
|
|
47
47
|
* new value based off the previous value.
|
|
48
48
|
*/
|
|
49
49
|
set(next) {
|
|
50
|
-
const
|
|
50
|
+
const oldState = this.get();
|
|
51
|
+
const newState = updater(next, oldState);
|
|
52
|
+
if (oldState === newState)
|
|
53
|
+
return;
|
|
51
54
|
void this.effects
|
|
52
55
|
.dispatch("set", newState)
|
|
53
56
|
.then(value => super.update(value));
|
|
@@ -48,9 +48,12 @@ export class SettableDerive extends Derive {
|
|
|
48
48
|
* new value based off the previous value.
|
|
49
49
|
*/
|
|
50
50
|
set(next) {
|
|
51
|
-
const
|
|
51
|
+
const oldState = this.get();
|
|
52
|
+
const newState = updater(next, oldState);
|
|
53
|
+
if (oldState === newState)
|
|
54
|
+
return;
|
|
52
55
|
this.setter({
|
|
53
|
-
value,
|
|
56
|
+
value: newState,
|
|
54
57
|
set: (atom, next) => {
|
|
55
58
|
const value = updater(next, atom.get());
|
|
56
59
|
atom.set(value);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yaasl/core",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.2",
|
|
4
4
|
"description": "yet another atomic store library (vanilla-js)",
|
|
5
5
|
"author": "PrettyCoffee",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"validate": "run-s lint test build"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@yaasl/utils": "0.10.
|
|
41
|
+
"@yaasl/utils": "0.10.2"
|
|
42
42
|
},
|
|
43
43
|
"eslintConfig": {
|
|
44
44
|
"extends": [
|