@mongez/atom 1.0.0 → 1.0.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.
@@ -0,0 +1,66 @@
1
+ import type { Atom, AtomActions, AtomOptions } from './types';
2
+ export type IndexOrCallback<Value> = number | ((value: Value, index: number, list: Value[]) => boolean);
3
+ interface AtomCollectionActions<Value> extends AtomActions<Value[]> {
4
+ /**
5
+ * Add items to the end of the array
6
+ */
7
+ push(this: Atom<Value[]>, ...items: Value[]): void;
8
+ /**
9
+ * Add items to the beginning of the array
10
+ */
11
+ unshift(this: Atom<Value[]>, ...items: Value[]): void;
12
+ /**
13
+ * Remove the last item from the array
14
+ */
15
+ pop(this: Atom<Value[]>): void;
16
+ /**
17
+ * Remove the first item from the array
18
+ */
19
+ shift(this: Atom<Value[]>): void;
20
+ /**
21
+ * Remove item from array either by index or callback
22
+ */
23
+ remove(this: Atom<Value[]>, indexOrCallback: IndexOrCallback<Value>): void;
24
+ /**
25
+ * Remove item from array by value
26
+ */
27
+ removeItem(this: Atom<Value[]>, item: Value): void;
28
+ /**
29
+ * Remove all items from array by value
30
+ */
31
+ removeAll(this: Atom<Value[]>, item: Value): Value[];
32
+ /**
33
+ * Get item from array either by index or callback
34
+ */
35
+ get(this: Atom<Value[]>, indexOrCallback: IndexOrCallback<Value>): Value | undefined;
36
+ /**
37
+ * Find index of item in array by callback
38
+ */
39
+ index(this: Atom<Value[]>, callback: (item: Value, index: number, array: Value[]) => boolean): number;
40
+ /**
41
+ * Map array items
42
+ * This will update the array with the new mapped array and trigger update
43
+ */
44
+ map(this: Atom<Value[]>, callback: (item: Value, index: number, array: Value[]) => Value): Value[];
45
+ /**
46
+ * Loop through array items
47
+ */
48
+ forEach(this: Atom<Value[]>, callback: (item: Value, index: number, array: Value[]) => void): void;
49
+ /**
50
+ * Replace item in array by index
51
+ */
52
+ replace(this: Atom<Value[]>, index: number, item: Value): void;
53
+ /**
54
+ * Get array length
55
+ */
56
+ length: number;
57
+ }
58
+ export type CollectionOptions<Value> = Omit<AtomOptions<Value[], AtomCollectionActions<Value>>, 'default'> & {
59
+ default?: Value[];
60
+ };
61
+ /**
62
+ * Create an atom collection
63
+ */
64
+ export declare function atomCollection<Value = any>(options: CollectionOptions<Value>): Atom<Value[], AtomCollectionActions<Value>>;
65
+ export {};
66
+ //# sourceMappingURL=atom-collection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atom-collection.d.ts","sourceRoot":"","sources":["../src/atom-collection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE9D,MAAM,MAAM,eAAe,CAAC,KAAK,IAC7B,MAAM,GACN,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,CAAC,CAAC;AAE9D,UAAU,qBAAqB,CAAC,KAAK,CAAE,SAAQ,WAAW,CAAC,KAAK,EAAE,CAAC;IACjE;;OAEG;IACH,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;IACnD;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;IACtD;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IAC/B;;OAEG;IACH,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IACjC;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,eAAe,EAAE,eAAe,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;IAC3E;;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K,EAAE,EAAE,qBAAqB,CAAC,KAAK,CAAC,CAAC,EAClD,SAAS,CACV,GAAG;IACF,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,GAAG,GAAG,EACxC,OAAO,EAAE,iBAAiB,CAAC,KAAK,CAAC,GAChC,IAAI,CAAC,KAAK,EAAE,EAAE,qBAAqB,CAAC,KAAK,CAAC,CAAC,CA8E7C"}
@@ -0,0 +1,71 @@
1
+ 'use strict';var atom=require('./atom.js');/**
2
+ * Create an atom collection
3
+ */
4
+ function atomCollection(options) {
5
+ return atom.createAtom({
6
+ key: options.key,
7
+ default: options.default ?? [],
8
+ actions: {
9
+ ...options.actions,
10
+ push(...items) {
11
+ this.update([...this.currentValue, ...items]);
12
+ },
13
+ pop() {
14
+ this.update(this.currentValue.slice(0, -1));
15
+ },
16
+ shift() {
17
+ this.update(this.currentValue.slice(1));
18
+ },
19
+ unshift(...items) {
20
+ this.update([...items, ...this.currentValue]);
21
+ },
22
+ remove(indexOrCallback) {
23
+ const index = typeof indexOrCallback === 'function'
24
+ ? this.value.findIndex(indexOrCallback)
25
+ : indexOrCallback;
26
+ if (index === -1)
27
+ return;
28
+ this.update(this.value.filter((_, i) => i !== index));
29
+ },
30
+ removeItem(item) {
31
+ const index = this.value.indexOf(item);
32
+ if (index === -1)
33
+ return;
34
+ // using splice
35
+ this.value.splice(index, 1);
36
+ this.update([...this.value]);
37
+ },
38
+ removeAll(item) {
39
+ return this.value.filter((value) => value !== item);
40
+ },
41
+ get(indexOrCallback) {
42
+ const index = typeof indexOrCallback === 'function'
43
+ ? this.value.findIndex(indexOrCallback)
44
+ : indexOrCallback;
45
+ return this.value[index];
46
+ },
47
+ index(callback) {
48
+ return this.value.findIndex(callback);
49
+ },
50
+ map(callback) {
51
+ const value = this.value.map(callback);
52
+ this.update(value);
53
+ return value;
54
+ },
55
+ forEach(callback) {
56
+ this.value.forEach(callback);
57
+ },
58
+ get length() {
59
+ return this.value?.length;
60
+ },
61
+ replace(index, item) {
62
+ this.update(this.value.map((value, i) => {
63
+ if (i === index) {
64
+ return item;
65
+ }
66
+ return value;
67
+ }));
68
+ },
69
+ },
70
+ });
71
+ }exports.atomCollection=atomCollection;//# sourceMappingURL=atom-collection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atom-collection.js","sources":["../src/atom-collection.ts"],"sourcesContent":[null],"names":["createAtom"],"mappings":"2CA+EA;;AAEG;AACG,SAAU,cAAc,CAC5B,OAAiC,EAAA;AAEjC,IAAA,OAAOA,eAAU,CAAwC;QACvD,GAAG,EAAE,OAAO,CAAC,GAAG;AAChB,QAAA,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,EAAE;AAC9B,QAAA,OAAO,EAAE;YACP,GAAG,OAAO,CAAC,OAAO;YAClB,IAAI,CAAC,GAAG,KAAc,EAAA;AACpB,gBAAA,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC,YAAY,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC;aAC/C;YACD,GAAG,GAAA;AACD,gBAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;aAC7C;YACD,KAAK,GAAA;AACH,gBAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;aACzC;YACD,OAAO,CAAC,GAAG,KAAc,EAAA;AACvB,gBAAA,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,EAAE,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;aAC/C;AACD,YAAA,MAAM,CAAC,eAAuC,EAAA;AAC5C,gBAAA,MAAM,KAAK,GACT,OAAO,eAAe,KAAK,UAAU;sBACjC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,eAAe,CAAC;sBACrC,e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;AACD,YAAA,OAAO,CAAC,QAA8D,EAAA;AACpE,gBAAA,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;aAC9B;AACD,YAAA,IAAI,MAAM,GAAA;AACR,gBAAA,OAAO,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC;aAC3B;YACD,OAAO,CAAC,KAAa,EAAE,IAAW,EAAA;AAChC,gBAAA,IAAI,CAAC,MAAM,CACT,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,KAAI;oBAC1B,IAAI,CAAC,KAAK,KAAK,EAAE;AACf,wBAAA,OAAO,IAAI,CAAC;AACb,qBAAA;AAED,oBAAA,OAAO,KAAK,CAAC;iBACd,CAAC,CACH,CAAC;aACH;AACF,SAAA;AACF,KAAA,CAAC,CAAC;AACL"}
package/cjs/atom.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ import { Atom, AtomActions, AtomOptions, AtomValue } from './types';
2
+ export declare const atoms: Record<string, Atom<any>>;
3
+ /**
4
+ * Get atom by name
5
+ */
6
+ export declare function getAtom<T>(name: string): Atom<T> | undefined;
7
+ /**
8
+ * Create a new atom
9
+ */
10
+ export declare function createAtom<Value = any, Actions extends AtomActions<Value> = AtomActions<Value>>(data: AtomOptions<AtomValue<Value>, Actions>): Atom<Value, Actions>;
11
+ /**
12
+ * Get all atoms list
13
+ */
14
+ export declare function atomsList(): Atom<any>[];
15
+ /**
16
+ * Return atoms in object format
17
+ */
18
+ export declare function atomsObject(): Record<string, Atom<any>>;
19
+ //# sourceMappingURL=atom.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atom.d.ts","sourceRoot":"","sources":["../src/atom.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,EAA6B,SAAS,EAAE,MAAM,SAAS,CAAC;AAE/F,eAAO,MAAM,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAM,CAAC;AAEnD;;GAEG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,SAAS,CAE5D;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,GAAG,GAAG,EAAE,OAAO,SAAS,WAAW,CAAC,KAAK,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,EAC7F,IAAI,EAAE,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,GAC3C,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAoLtB;AAED;;GAEG;AACH,wBAAgB,SAAS,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAEvC;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAEvD"}
package/cjs/atom.js ADDED
@@ -0,0 +1,178 @@
1
+ 'use strict';var events=require('@mongez/events'),reinforcements=require('@mongez/reinforcements');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var events__default=/*#__PURE__*/_interopDefault(events);/* eslint-disable no-multi-assign */
2
+ /* eslint-disable guard-for-in */
3
+ /* eslint-disable @typescript-eslint/no-shadow */
4
+ /* eslint-disable prefer-template */
5
+ const atoms = {};
6
+ /**
7
+ * Get atom by name
8
+ */
9
+ function getAtom(name) {
10
+ return atoms[name];
11
+ }
12
+ /**
13
+ * Create a new atom
14
+ */
15
+ function createAtom(data) {
16
+ let defaultValue = data.default;
17
+ let atomValue = data.default;
18
+ let atomValueIsObject = false;
19
+ if (defaultValue && typeof defaultValue === 'object') {
20
+ atomValue = defaultValue = reinforcements.clone(defaultValue);
21
+ atomValueIsObject = true;
22
+ }
23
+ const atomType = Array.isArray(defaultValue) ? 'array' : typeof defaultValue;
24
+ const atomEvent = `atoms.${data.key}`;
25
+ const event = (type) => `${atomEvent}.${type}`;
26
+ const watchers = {};
27
+ const atomKey = data.key;
28
+ const atom = {
29
+ default: defaultValue,
30
+ currentValue: atomValue,
31
+ key: atomKey,
32
+ get type() {
33
+ return atomType;
34
+ },
35
+ watch(key, callback) {
36
+ if (!watchers[key]) {
37
+ watchers[key] = [];
38
+ }
39
+ watchers[key].push(callback);
40
+ const callbackIndex = watchers[key].length - 1;
41
+ return {
42
+ unsubscribe: () => {
43
+ watchers[key].splice(callbackIndex, 1);
44
+ },
45
+ };
46
+ },
47
+ get defaultValue() {
48
+ return this.default;
49
+ },
50
+ get value() {
51
+ return this.currentValue;
52
+ },
53
+ change(key, newValue) {
54
+ this.update({
55
+ ...this.currentValue,
56
+ [key]: newValue,
57
+ });
58
+ },
59
+ silentChange(key, newValue) {
60
+ this.silentUpdate({
61
+ ...this.currentValue,
62
+ [key]: newValue,
63
+ });
64
+ },
65
+ merge(newValue) {
66
+ this.update({
67
+ ...this.currentValue,
68
+ ...newValue,
69
+ });
70
+ },
71
+ update(newValue) {
72
+ if (newValue === this.currentValue)
73
+ return;
74
+ const oldValue = this.currentValue;
75
+ let updatedValue;
76
+ if (typeof newValue === 'function') {
77
+ updatedValue = newValue(oldValue, this);
78
+ }
79
+ else {
80
+ updatedValue = newValue;
81
+ }
82
+ if (data.beforeUpdate) {
83
+ updatedValue = data.beforeUpdate(updatedValue, oldValue, this);
84
+ }
85
+ this.currentValue = updatedValue;
86
+ events__default.default.trigger(event('update'), this.currentValue, oldValue, this);
87
+ if (atomValueIsObject) {
88
+ for (const key in watchers) {
89
+ const keyOldValue = reinforcements.get(oldValue, key);
90
+ const keyNewValue = reinforcements.get(newValue, key);
91
+ if (keyOldValue !== keyNewValue) {
92
+ watchers[key].forEach((callback) => callback(keyNewValue, keyOldValue));
93
+ }
94
+ }
95
+ }
96
+ },
97
+ silentUpdate(newValue) {
98
+ if (newValue === this.currentValue)
99
+ return;
100
+ const oldValue = this.currentValue;
101
+ if (typeof newValue === 'function') {
102
+ newValue = newValue(oldValue, this);
103
+ }
104
+ if (data.beforeUpdate) {
105
+ newValue = data.beforeUpdate(newValue, oldValue, this);
106
+ }
107
+ this.currentValue = newValue;
108
+ },
109
+ onChange(callback) {
110
+ return events__default.default.subscribe(event('update'), callback);
111
+ },
112
+ onReset(callback) {
113
+ return events__default.default.subscribe(event('reset'), callback);
114
+ },
115
+ get(key, defaultValue) {
116
+ if (data.get) {
117
+ return data.get(key, defaultValue, this.currentValue);
118
+ }
119
+ const value = reinforcements.get(this.currentValue, key, defaultValue);
120
+ // if the value is bindable, then bind the current value to be used as `this`
121
+ return value?.bind ? value.bind(this.currentValue) : value;
122
+ },
123
+ destroy() {
124
+ events__default.default.trigger(event('delete'), this);
125
+ events__default.default.unsubscribeNamespace(atomEvent);
126
+ delete atoms[this.key];
127
+ },
128
+ onDestroy(callback) {
129
+ return events__default.default.subscribe(`atoms.${this.key}.delete`, callback);
130
+ },
131
+ reset() {
132
+ const update = this.update(this.defaultValue);
133
+ events__default.default.trigger(event('reset'), this);
134
+ return update;
135
+ },
136
+ /**
137
+ * Reset the value without triggering the update event
138
+ * But this will trigger the reset event
139
+ */
140
+ silentReset() {
141
+ this.currentValue = reinforcements.clone(this.defaultValue);
142
+ events__default.default.trigger(event('reset'), this);
143
+ return this;
144
+ },
145
+ clone() {
146
+ return createAtom({
147
+ key: this.key + 'Cloned' + reinforcements.Random.int(1000, 9999),
148
+ default: reinforcements.clone(this.currentValue),
149
+ beforeUpdate: data.beforeUpdate,
150
+ get: data.get,
151
+ onUpdate: data.onUpdate,
152
+ });
153
+ },
154
+ };
155
+ // Bind actions to the atom instance
156
+ if (data.actions) {
157
+ Object.keys(data.actions).forEach((actionKey) => {
158
+ atom[actionKey] = data.actions[actionKey].bind(atom);
159
+ });
160
+ }
161
+ if (data.onUpdate) {
162
+ events__default.default.subscribe(event('update'), data.onUpdate.bind(atom));
163
+ }
164
+ atoms[atomKey] = atom;
165
+ return atom;
166
+ }
167
+ /**
168
+ * Get all atoms list
169
+ */
170
+ function atomsList() {
171
+ return Object.values(atoms);
172
+ }
173
+ /**
174
+ * Return atoms in object format
175
+ */
176
+ function atomsObject() {
177
+ return atoms;
178
+ }exports.atoms=atoms;exports.atomsList=atomsList;exports.atomsObject=atomsObject;exports.createAtom=createAtom;exports.getAtom=getAtom;//# sourceMappingURL=atom.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atom.js","sources":["../src/atom.ts"],"sourcesContent":[null],"names":["clone","events","get","Random"],"mappings":"6NAAA;AACA;AACA;AACA;AAKO,MAAM,KAAK,GAA8B,GAAG;AAEnD;;AAEG;AACG,SAAU,OAAO,CAAI,IAAY,EAAA;AACrC,IAAA,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC;AACrB,CAAC;AAED;;AAEG;AACG,SAAU,UAAU,CACxB,IAA4C,EAAA;AAE5C,IAAA,IAAI,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC;AAChC,IAAA,IAAI,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC;IAE7B,IAAI,iBAAiB,GAAG,KAAK,CAAC;AAE9B,IAAA,IAAI,YAAY,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE;AACpD,QAAA,SAAS,GAAG,YAAY,GAAGA,oBAAK,CAAC,YAAY,CAAC,CAAC;QAC/C,iBAAiB,GAAG,IAAI,CAAC;AAC1B,KAAA;AAED,IAAA,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,OAAO,GAAG,OAAO,YAAY,CAAC;AAE7E,IAAA,MAAM,SAAS,GAAG,CAAA,MAAA,EAAS,IAAI,CAAC,GAAG,EAAE,CAAC;AAEtC,IAAA,MAAM,KAAK,GAAG,CAAC,IAAY,KAAa,CAAA,EAAG,SAAS,CAAA,CAAA,EAAI,IAAI,CAAA,CAAE,CAAC;IAE/D,MAAM,QAAQ,GAAQ,EAAE,CAAC;AAEzB,IAAA,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC;AAEzB,IAAA,MAAM,IAAI,GAAyB;AACj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AC,IAAI,CAAC,CAAC;AACjE,SAAC,CAAC,CAAC;AACJ,KAAA;IAED,IAAI,IAAI,CAAC,QAAQ,EAAE;AACjB,QAAAC,uBAAM,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AAC7D,KAAA;AAED,IAAA,KAAK,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;AAEtB,IAAA,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;AAEG;SACa,SAAS,GAAA;AACvB,IAAA,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED;;AAEG;SACa,WAAW,GAAA;AACzB,IAAA,OAAO,KAAK,CAAC;AACf"}
@@ -0,0 +1,2 @@
1
+ export * from './atom-collection';
2
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
package/cjs/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './atom';
2
+ export * from './helpers';
3
+ export * from './types';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
package/cjs/index.js ADDED
@@ -0,0 +1 @@
1
+ 'use strict';var atom=require('./atom.js'),atomCollection=require('./atom-collection.js');exports.atoms=atom.atoms;exports.atomsList=atom.atomsList;exports.atomsObject=atom.atomsObject;exports.createAtom=atom.createAtom;exports.getAtom=atom.getAtom;exports.atomCollection=atomCollection.atomCollection;//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
package/cjs/types.d.ts ADDED
@@ -0,0 +1,143 @@
1
+ import { type EventSubscription } from '@mongez/events';
2
+ export type AtomPartialChangeCallback = (newValue: any, oldValue: any, atom: Atom<any>) => void;
3
+ export type AtomValue<Value> = Value;
4
+ export type AtomActionMethod<Value> = (...args: any[]) => void | Value | Promise<void> | Promise<Value>;
5
+ export type AtomActions<Value> = {
6
+ [key: string]: ((this: Atom<Value>, ...args: any[]) => any) | any;
7
+ };
8
+ /**
9
+ * Atom Options
10
+ */
11
+ export type AtomOptions<Value = any, Actions extends AtomActions<Value> = {}> = {
12
+ /**
13
+ * Atom unique key
14
+ */
15
+ key: string;
16
+ /**
17
+ * Atom default value
18
+ */
19
+ default: Value | Partial<Value>;
20
+ /**
21
+ * Make adjustments on the value before updating the atom
22
+ */
23
+ beforeUpdate?: (newValue: Value, oldValue: Value, atom: Atom<AtomValue<Value>, Actions>) => Value;
24
+ /**
25
+ * Triggered when atom is updated
26
+ */
27
+ onUpdate?: (callback: AtomChangeCallback<Value, Actions>) => EventSubscription;
28
+ /**
29
+ * Set getter function, works only when atom's value is object
30
+ */
31
+ get?: (key: string, defaultValue?: Value, atomValue?: Value) => Value;
32
+ /**
33
+ * Atom actions, this is used to add methods to the atom instance
34
+ * i.e: actions: { increment: () => this.update(this.value + 1) }, usage will be atom.increment()
35
+ */
36
+ actions?: Actions & ThisType<Atom<Value, Actions>>;
37
+ };
38
+ export type AtomChangeCallback<Value, Actions extends AtomActions<Value>> = (newValue: Value, oldValue: Value, atom: Atom<Value, Actions>) => void;
39
+ /**
40
+ * The Atom Instance
41
+ */
42
+ export type Atom<Value = any, Actions extends AtomActions<Value> = {}> = {
43
+ /**
44
+ * Atom unique key, set by the user
45
+ */
46
+ key: string;
47
+ /**
48
+ * Atom default value, set by the user
49
+ */
50
+ default: Value;
51
+ /**
52
+ * Atom current value, initialized with the passed default value
53
+ */
54
+ currentValue: Value;
55
+ /**
56
+ * Reset the atom value
57
+ */
58
+ reset: () => void;
59
+ /**
60
+ * Reset the atom without triggering the update event
61
+ */
62
+ silentReset: () => void;
63
+ /**
64
+ * Update atom value, the function accepts a new value,
65
+ * or it can accept a callback that passes the old value and the atom instance
66
+ * This will trigger atom event update
67
+ */
68
+ update: (value: ((oldValue: Value, atom: Atom<Value>) => Value) | Value) => void;
69
+ /**
70
+ * Update atom value without triggering the update event
71
+ */
72
+ silentUpdate: (value: ((oldValue: Value, atom: Atom<Value>) => Value) | Value) => void;
73
+ /**
74
+ * Merge the given object with current atom value
75
+ * This is sort of partial update that works only if atom's value is an object
76
+ */
77
+ merge: (value: Partial<Value>) => void;
78
+ /**
79
+ * Change only one key of the atom
80
+ * Works only if atom's value is an object
81
+ */
82
+ change: <T extends keyof Value>(key: T, newValue: any) => void;
83
+ /**
84
+ * Change only one key of the atom without triggering the update event
85
+ * Works only if atom's value is an object
86
+ */
87
+ silentChange: <T extends keyof Value>(key: T, newValue: any) => void;
88
+ /**
89
+ * Get current value
90
+ */
91
+ readonly value: Value;
92
+ /**
93
+ * Get default value that started with atom creation
94
+ */
95
+ readonly defaultValue: Value;
96
+ /**
97
+ * Destroy the atom and remove it from atmos list
98
+ * This will trigger an atom destroy event then unsubscribe all atom events
99
+ */
100
+ destroy: () => void;
101
+ /**
102
+ * An event listener to the atom value change
103
+ * The callback accepts the new updated value, the old value and an atom instance
104
+ */
105
+ onChange: (callback: AtomChangeCallback<Value, Actions>) => EventSubscription;
106
+ /**
107
+ * Watch for atom value change
108
+ * This can be used only when atom's default value is an object or an array
109
+ * The key accepts dot.notation syntax
110
+ */
111
+ watch: <T extends keyof Value>(key: T, callback: AtomPartialChangeCallback) => EventSubscription;
112
+ /**
113
+ * An event listener to the atom destruction
114
+ */
115
+ onDestroy(callback: (atom: Atom<Value>) => void): EventSubscription;
116
+ /**
117
+ * Called when reset is called
118
+ */
119
+ onReset(callback: (atom: Atom<Value>) => void): EventSubscription;
120
+ /**
121
+ * Get value from atom's value
122
+ * Works only if atom's value is an object
123
+ */
124
+ get<T extends keyof Value>(key: T, defaultValue?: any): Value[T];
125
+ /**
126
+ * Clone the atom
127
+ * This will return a new atom but the key will be suffixed with Clone{Number}
128
+ * i.e atom name is: user5122
129
+ * cloned atom name will be: userClone
130
+ */
131
+ clone: () => Atom<Value, Actions>;
132
+ /**
133
+ * Get the atom's value type
134
+ */
135
+ readonly type: string;
136
+ /**
137
+ * Get the atom's value length
138
+ *
139
+ * Works only if atom's value is an array or a string
140
+ */
141
+ readonly length: number;
142
+ } & Actions;
143
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD,MAAM,MAAM,yBAAyB,GAAG,CAAC,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;AAEhG,MAAM,MAAM,SAAS,CAAC,KAAK,IAAI,KAAK,CAAC;AAErC,MAAM,MAAM,gBAAgB,CAAC,KAAK,IAAI,CACpC,GAAG,IAAI,EAAE,GAAG,EAAE,KACX,IAAI,GAAG,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;AAEnD,MAAM,MAAM,WAAW,CAAC,KAAK,IAAI;IAC/B,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,GAAG,GAAG,CAAC;CACnE,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,KAAK,GAAG,GAAG,EAAE,OAAO,SAAS,WAAW,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI;IAC9E;;OAEG;IACH,GAAG,EAAE,MAAM,C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AI,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,IAAI,GAAG,iBAAiB,CAAC;IAElE;;;OAGG;IACH,GAAG,CAAC,CAAC,SAAS,MAAM,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,YAAY,CAAC,EAAE,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IAEjE;;;;;OAKG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAElC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,GAAG,OAAO,CAAC"}
@@ -0,0 +1,66 @@
1
+ import type { Atom, AtomActions, AtomOptions } from './types';
2
+ export type IndexOrCallback<Value> = number | ((value: Value, index: number, list: Value[]) => boolean);
3
+ interface AtomCollectionActions<Value> extends AtomActions<Value[]> {
4
+ /**
5
+ * Add items to the end of the array
6
+ */
7
+ push(this: Atom<Value[]>, ...items: Value[]): void;
8
+ /**
9
+ * Add items to the beginning of the array
10
+ */
11
+ unshift(this: Atom<Value[]>, ...items: Value[]): void;
12
+ /**
13
+ * Remove the last item from the array
14
+ */
15
+ pop(this: Atom<Value[]>): void;
16
+ /**
17
+ * Remove the first item from the array
18
+ */
19
+ shift(this: Atom<Value[]>): void;
20
+ /**
21
+ * Remove item from array either by index or callback
22
+ */
23
+ remove(this: Atom<Value[]>, indexOrCallback: IndexOrCallback<Value>): void;
24
+ /**
25
+ * Remove item from array by value
26
+ */
27
+ removeItem(this: Atom<Value[]>, item: Value): void;
28
+ /**
29
+ * Remove all items from array by value
30
+ */
31
+ removeAll(this: Atom<Value[]>, item: Value): Value[];
32
+ /**
33
+ * Get item from array either by index or callback
34
+ */
35
+ get(this: Atom<Value[]>, indexOrCallback: IndexOrCallback<Value>): Value | undefined;
36
+ /**
37
+ * Find index of item in array by callback
38
+ */
39
+ index(this: Atom<Value[]>, callback: (item: Value, index: number, array: Value[]) => boolean): number;
40
+ /**
41
+ * Map array items
42
+ * This will update the array with the new mapped array and trigger update
43
+ */
44
+ map(this: Atom<Value[]>, callback: (item: Value, index: number, array: Value[]) => Value): Value[];
45
+ /**
46
+ * Loop through array items
47
+ */
48
+ forEach(this: Atom<Value[]>, callback: (item: Value, index: number, array: Value[]) => void): void;
49
+ /**
50
+ * Replace item in array by index
51
+ */
52
+ replace(this: Atom<Value[]>, index: number, item: Value): void;
53
+ /**
54
+ * Get array length
55
+ */
56
+ length: number;
57
+ }
58
+ export type CollectionOptions<Value> = Omit<AtomOptions<Value[], AtomCollectionActions<Value>>, 'default'> & {
59
+ default?: Value[];
60
+ };
61
+ /**
62
+ * Create an atom collection
63
+ */
64
+ export declare function atomCollection<Value = any>(options: CollectionOptions<Value>): Atom<Value[], AtomCollectionActions<Value>>;
65
+ export {};
66
+ //# sourceMappingURL=atom-collection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atom-collection.d.ts","sourceRoot":"","sources":["../src/atom-collection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE9D,MAAM,MAAM,eAAe,CAAC,KAAK,IAC7B,MAAM,GACN,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,CAAC,CAAC;AAE9D,UAAU,qBAAqB,CAAC,KAAK,CAAE,SAAQ,WAAW,CAAC,KAAK,EAAE,CAAC;IACjE;;OAEG;IACH,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;IACnD;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE,GAAG,IAAI,CA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,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,IAAI,GAC7D,IAAI,CAAC;IACR;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC;IAC/D;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,iBAAiB,CAAC,KAAK,IAAI,IAAI,CACzC,WAAW,CAAC,KAAK,EAAE,EAAE,qBAAqB,CAAC,KAAK,CAAC,CAAC,EAClD,SAAS,CACV,GAAG;IACF,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,GAAG,GAAG,EACxC,OAAO,EAAE,iBAAiB,CAAC,KAAK,CAAC,GAChC,IAAI,CAAC,KAAK,EAAE,EAAE,qBAAqB,CAAC,KAAK,CAAC,CAAC,CA8E7C"}
@@ -0,0 +1,71 @@
1
+ import {createAtom}from'./atom.js';/**
2
+ * Create an atom collection
3
+ */
4
+ function atomCollection(options) {
5
+ return createAtom({
6
+ key: options.key,
7
+ default: options.default ?? [],
8
+ actions: {
9
+ ...options.actions,
10
+ push(...items) {
11
+ this.update([...this.currentValue, ...items]);
12
+ },
13
+ pop() {
14
+ this.update(this.currentValue.slice(0, -1));
15
+ },
16
+ shift() {
17
+ this.update(this.currentValue.slice(1));
18
+ },
19
+ unshift(...items) {
20
+ this.update([...items, ...this.currentValue]);
21
+ },
22
+ remove(indexOrCallback) {
23
+ const index = typeof indexOrCallback === 'function'
24
+ ? this.value.findIndex(indexOrCallback)
25
+ : indexOrCallback;
26
+ if (index === -1)
27
+ return;
28
+ this.update(this.value.filter((_, i) => i !== index));
29
+ },
30
+ removeItem(item) {
31
+ const index = this.value.indexOf(item);
32
+ if (index === -1)
33
+ return;
34
+ // using splice
35
+ this.value.splice(index, 1);
36
+ this.update([...this.value]);
37
+ },
38
+ removeAll(item) {
39
+ return this.value.filter((value) => value !== item);
40
+ },
41
+ get(indexOrCallback) {
42
+ const index = typeof indexOrCallback === 'function'
43
+ ? this.value.findIndex(indexOrCallback)
44
+ : indexOrCallback;
45
+ return this.value[index];
46
+ },
47
+ index(callback) {
48
+ return this.value.findIndex(callback);
49
+ },
50
+ map(callback) {
51
+ const value = this.value.map(callback);
52
+ this.update(value);
53
+ return value;
54
+ },
55
+ forEach(callback) {
56
+ this.value.forEach(callback);
57
+ },
58
+ get length() {
59
+ return this.value?.length;
60
+ },
61
+ replace(index, item) {
62
+ this.update(this.value.map((value, i) => {
63
+ if (i === index) {
64
+ return item;
65
+ }
66
+ return value;
67
+ }));
68
+ },
69
+ },
70
+ });
71
+ }export{atomCollection};//# sourceMappingURL=atom-collection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atom-collection.js","sources":["../src/atom-collection.ts"],"sourcesContent":[null],"names":[],"mappings":"mCA+EA;;AAEG;AACG,SAAU,cAAc,CAC5B,OAAiC,EAAA;AAEjC,IAAA,OAAO,UAAU,CAAwC;QACvD,GAAG,EAAE,OAAO,CAAC,GAAG;AAChB,QAAA,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,EAAE;AAC9B,QAAA,OAAO,EAAE;YACP,GAAG,OAAO,CAAC,OAAO;YAClB,IAAI,CAAC,GAAG,KAAc,EAAA;AACpB,gBAAA,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC,YAAY,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC;aAC/C;YACD,GAAG,GAAA;AACD,gBAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;aAC7C;YACD,KAAK,GAAA;AACH,gBAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;aACz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CAAC,QAAiE,EAAA;gBACrE,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;aACvC;AACD,YAAA,GAAG,CAAC,QAA+D,EAAA;gBACjE,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAEvC,gBAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAEnB,gBAAA,OAAO,KAAK,CAAC;aACd;AACD,YAAA,OAAO,CAAC,QAA8D,EAAA;AACpE,gBAAA,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;aAC9B;AACD,YAAA,IAAI,MAAM,GAAA;AACR,gBAAA,OAAO,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC;aAC3B;YACD,OAAO,CAAC,KAAa,EAAE,IAAW,EAAA;AAChC,gBAAA,IAAI,CAAC,MAAM,CACT,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,KAAI;oBAC1B,IAAI,CAAC,KAAK,KAAK,EAAE;AACf,wBAAA,OAAO,IAAI,CAAC;AACb,qBAAA;AAED,oBAAA,OAAO,KAAK,CAAC;iBACd,CAAC,CACH,CAAC;aACH;AACF,SAAA;AACF,KAAA,CAAC,CAAC;AACL"}
package/esm/atom.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ import { Atom, AtomActions, AtomOptions, AtomValue } from './types';
2
+ export declare const atoms: Record<string, Atom<any>>;
3
+ /**
4
+ * Get atom by name
5
+ */
6
+ export declare function getAtom<T>(name: string): Atom<T> | undefined;
7
+ /**
8
+ * Create a new atom
9
+ */
10
+ export declare function createAtom<Value = any, Actions extends AtomActions<Value> = AtomActions<Value>>(data: AtomOptions<AtomValue<Value>, Actions>): Atom<Value, Actions>;
11
+ /**
12
+ * Get all atoms list
13
+ */
14
+ export declare function atomsList(): Atom<any>[];
15
+ /**
16
+ * Return atoms in object format
17
+ */
18
+ export declare function atomsObject(): Record<string, Atom<any>>;
19
+ //# sourceMappingURL=atom.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atom.d.ts","sourceRoot":"","sources":["../src/atom.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,EAA6B,SAAS,EAAE,MAAM,SAAS,CAAC;AAE/F,eAAO,MAAM,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAM,CAAC;AAEnD;;GAEG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,SAAS,CAE5D;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,GAAG,GAAG,EAAE,OAAO,SAAS,WAAW,CAAC,KAAK,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,EAC7F,IAAI,EAAE,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,GAC3C,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAoLtB;AAED;;GAEG;AACH,wBAAgB,SAAS,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAEvC;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAEvD"}
package/esm/atom.js ADDED
@@ -0,0 +1,178 @@
1
+ import events from'@mongez/events';import {clone,get,Random}from'@mongez/reinforcements';/* eslint-disable no-multi-assign */
2
+ /* eslint-disable guard-for-in */
3
+ /* eslint-disable @typescript-eslint/no-shadow */
4
+ /* eslint-disable prefer-template */
5
+ const atoms = {};
6
+ /**
7
+ * Get atom by name
8
+ */
9
+ function getAtom(name) {
10
+ return atoms[name];
11
+ }
12
+ /**
13
+ * Create a new atom
14
+ */
15
+ function createAtom(data) {
16
+ let defaultValue = data.default;
17
+ let atomValue = data.default;
18
+ let atomValueIsObject = false;
19
+ if (defaultValue && typeof defaultValue === 'object') {
20
+ atomValue = defaultValue = clone(defaultValue);
21
+ atomValueIsObject = true;
22
+ }
23
+ const atomType = Array.isArray(defaultValue) ? 'array' : typeof defaultValue;
24
+ const atomEvent = `atoms.${data.key}`;
25
+ const event = (type) => `${atomEvent}.${type}`;
26
+ const watchers = {};
27
+ const atomKey = data.key;
28
+ const atom = {
29
+ default: defaultValue,
30
+ currentValue: atomValue,
31
+ key: atomKey,
32
+ get type() {
33
+ return atomType;
34
+ },
35
+ watch(key, callback) {
36
+ if (!watchers[key]) {
37
+ watchers[key] = [];
38
+ }
39
+ watchers[key].push(callback);
40
+ const callbackIndex = watchers[key].length - 1;
41
+ return {
42
+ unsubscribe: () => {
43
+ watchers[key].splice(callbackIndex, 1);
44
+ },
45
+ };
46
+ },
47
+ get defaultValue() {
48
+ return this.default;
49
+ },
50
+ get value() {
51
+ return this.currentValue;
52
+ },
53
+ change(key, newValue) {
54
+ this.update({
55
+ ...this.currentValue,
56
+ [key]: newValue,
57
+ });
58
+ },
59
+ silentChange(key, newValue) {
60
+ this.silentUpdate({
61
+ ...this.currentValue,
62
+ [key]: newValue,
63
+ });
64
+ },
65
+ merge(newValue) {
66
+ this.update({
67
+ ...this.currentValue,
68
+ ...newValue,
69
+ });
70
+ },
71
+ update(newValue) {
72
+ if (newValue === this.currentValue)
73
+ return;
74
+ const oldValue = this.currentValue;
75
+ let updatedValue;
76
+ if (typeof newValue === 'function') {
77
+ updatedValue = newValue(oldValue, this);
78
+ }
79
+ else {
80
+ updatedValue = newValue;
81
+ }
82
+ if (data.beforeUpdate) {
83
+ updatedValue = data.beforeUpdate(updatedValue, oldValue, this);
84
+ }
85
+ this.currentValue = updatedValue;
86
+ events.trigger(event('update'), this.currentValue, oldValue, this);
87
+ if (atomValueIsObject) {
88
+ for (const key in watchers) {
89
+ const keyOldValue = get(oldValue, key);
90
+ const keyNewValue = get(newValue, key);
91
+ if (keyOldValue !== keyNewValue) {
92
+ watchers[key].forEach((callback) => callback(keyNewValue, keyOldValue));
93
+ }
94
+ }
95
+ }
96
+ },
97
+ silentUpdate(newValue) {
98
+ if (newValue === this.currentValue)
99
+ return;
100
+ const oldValue = this.currentValue;
101
+ if (typeof newValue === 'function') {
102
+ newValue = newValue(oldValue, this);
103
+ }
104
+ if (data.beforeUpdate) {
105
+ newValue = data.beforeUpdate(newValue, oldValue, this);
106
+ }
107
+ this.currentValue = newValue;
108
+ },
109
+ onChange(callback) {
110
+ return events.subscribe(event('update'), callback);
111
+ },
112
+ onReset(callback) {
113
+ return events.subscribe(event('reset'), callback);
114
+ },
115
+ get(key, defaultValue) {
116
+ if (data.get) {
117
+ return data.get(key, defaultValue, this.currentValue);
118
+ }
119
+ const value = get(this.currentValue, key, defaultValue);
120
+ // if the value is bindable, then bind the current value to be used as `this`
121
+ return value?.bind ? value.bind(this.currentValue) : value;
122
+ },
123
+ destroy() {
124
+ events.trigger(event('delete'), this);
125
+ events.unsubscribeNamespace(atomEvent);
126
+ delete atoms[this.key];
127
+ },
128
+ onDestroy(callback) {
129
+ return events.subscribe(`atoms.${this.key}.delete`, callback);
130
+ },
131
+ reset() {
132
+ const update = this.update(this.defaultValue);
133
+ events.trigger(event('reset'), this);
134
+ return update;
135
+ },
136
+ /**
137
+ * Reset the value without triggering the update event
138
+ * But this will trigger the reset event
139
+ */
140
+ silentReset() {
141
+ this.currentValue = clone(this.defaultValue);
142
+ events.trigger(event('reset'), this);
143
+ return this;
144
+ },
145
+ clone() {
146
+ return createAtom({
147
+ key: this.key + 'Cloned' + Random.int(1000, 9999),
148
+ default: clone(this.currentValue),
149
+ beforeUpdate: data.beforeUpdate,
150
+ get: data.get,
151
+ onUpdate: data.onUpdate,
152
+ });
153
+ },
154
+ };
155
+ // Bind actions to the atom instance
156
+ if (data.actions) {
157
+ Object.keys(data.actions).forEach((actionKey) => {
158
+ atom[actionKey] = data.actions[actionKey].bind(atom);
159
+ });
160
+ }
161
+ if (data.onUpdate) {
162
+ events.subscribe(event('update'), data.onUpdate.bind(atom));
163
+ }
164
+ atoms[atomKey] = atom;
165
+ return atom;
166
+ }
167
+ /**
168
+ * Get all atoms list
169
+ */
170
+ function atomsList() {
171
+ return Object.values(atoms);
172
+ }
173
+ /**
174
+ * Return atoms in object format
175
+ */
176
+ function atomsObject() {
177
+ return atoms;
178
+ }export{atoms,atomsList,atomsObject,createAtom,getAtom};//# sourceMappingURL=atom.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atom.js","sources":["../src/atom.ts"],"sourcesContent":[null],"names":[],"mappings":"yFAAA;AACA;AACA;AACA;AAKO,MAAM,KAAK,GAA8B,GAAG;AAEnD;;AAEG;AACG,SAAU,OAAO,CAAI,IAAY,EAAA;AACrC,IAAA,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC;AACrB,CAAC;AAED;;AAEG;AACG,SAAU,UAAU,CACxB,IAA4C,EAAA;AAE5C,IAAA,IAAI,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC;AAChC,IAAA,IAAI,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC;IAE7B,IAAI,iBAAiB,GAAG,KAAK,CAAC;AAE9B,IAAA,IAAI,YAAY,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE;AACpD,QAAA,SAAS,GAAG,YAAY,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC;QAC/C,iBAAiB,GAAG,IAAI,CAAC;AAC1B,KAAA;AAED,IAAA,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,OAAO,GAAG,OAAO,YAAY,CAAC;AAE7E,IAAA,MAAM,SAAS,GAAG,CAAA,MAAA,EAAS,IAAI,CAAC,GAAG,EAAE,CAAC;AAEtC,IAAA,MAAM,KAAK,GAAG,CAAC,IAAY,KAAa,CAAA,EAAG,SAAS,CAAA,CAAA,EAAI,IAAI,CAAA,CAAE,CAAC;IAE/D,MAAM,QAAQ,GAAQ,EAAE,CAAC;AAEzB,IAAA,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AAC,OAAQ,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACjE,SAAC,CAAC,CAAC;AACJ,KAAA;IAED,IAAI,IAAI,CAAC,QAAQ,EAAE;AACjB,QAAA,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AAC7D,KAAA;AAED,IAAA,KAAK,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;AAEtB,IAAA,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;AAEG;SACa,SAAS,GAAA;AACvB,IAAA,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED;;AAEG;SACa,WAAW,GAAA;AACzB,IAAA,OAAO,KAAK,CAAC;AACf"}
@@ -0,0 +1,2 @@
1
+ export * from './atom-collection';
2
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
package/esm/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './atom';
2
+ export * from './helpers';
3
+ export * from './types';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
package/esm/index.js ADDED
@@ -0,0 +1 @@
1
+ export{atoms,atomsList,atomsObject,createAtom,getAtom}from'./atom.js';export{atomCollection}from'./atom-collection.js';//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
package/esm/types.d.ts ADDED
@@ -0,0 +1,143 @@
1
+ import { type EventSubscription } from '@mongez/events';
2
+ export type AtomPartialChangeCallback = (newValue: any, oldValue: any, atom: Atom<any>) => void;
3
+ export type AtomValue<Value> = Value;
4
+ export type AtomActionMethod<Value> = (...args: any[]) => void | Value | Promise<void> | Promise<Value>;
5
+ export type AtomActions<Value> = {
6
+ [key: string]: ((this: Atom<Value>, ...args: any[]) => any) | any;
7
+ };
8
+ /**
9
+ * Atom Options
10
+ */
11
+ export type AtomOptions<Value = any, Actions extends AtomActions<Value> = {}> = {
12
+ /**
13
+ * Atom unique key
14
+ */
15
+ key: string;
16
+ /**
17
+ * Atom default value
18
+ */
19
+ default: Value | Partial<Value>;
20
+ /**
21
+ * Make adjustments on the value before updating the atom
22
+ */
23
+ beforeUpdate?: (newValue: Value, oldValue: Value, atom: Atom<AtomValue<Value>, Actions>) => Value;
24
+ /**
25
+ * Triggered when atom is updated
26
+ */
27
+ onUpdate?: (callback: AtomChangeCallback<Value, Actions>) => EventSubscription;
28
+ /**
29
+ * Set getter function, works only when atom's value is object
30
+ */
31
+ get?: (key: string, defaultValue?: Value, atomValue?: Value) => Value;
32
+ /**
33
+ * Atom actions, this is used to add methods to the atom instance
34
+ * i.e: actions: { increment: () => this.update(this.value + 1) }, usage will be atom.increment()
35
+ */
36
+ actions?: Actions & ThisType<Atom<Value, Actions>>;
37
+ };
38
+ export type AtomChangeCallback<Value, Actions extends AtomActions<Value>> = (newValue: Value, oldValue: Value, atom: Atom<Value, Actions>) => void;
39
+ /**
40
+ * The Atom Instance
41
+ */
42
+ export type Atom<Value = any, Actions extends AtomActions<Value> = {}> = {
43
+ /**
44
+ * Atom unique key, set by the user
45
+ */
46
+ key: string;
47
+ /**
48
+ * Atom default value, set by the user
49
+ */
50
+ default: Value;
51
+ /**
52
+ * Atom current value, initialized with the passed default value
53
+ */
54
+ currentValue: Value;
55
+ /**
56
+ * Reset the atom value
57
+ */
58
+ reset: () => void;
59
+ /**
60
+ * Reset the atom without triggering the update event
61
+ */
62
+ silentReset: () => void;
63
+ /**
64
+ * Update atom value, the function accepts a new value,
65
+ * or it can accept a callback that passes the old value and the atom instance
66
+ * This will trigger atom event update
67
+ */
68
+ update: (value: ((oldValue: Value, atom: Atom<Value>) => Value) | Value) => void;
69
+ /**
70
+ * Update atom value without triggering the update event
71
+ */
72
+ silentUpdate: (value: ((oldValue: Value, atom: Atom<Value>) => Value) | Value) => void;
73
+ /**
74
+ * Merge the given object with current atom value
75
+ * This is sort of partial update that works only if atom's value is an object
76
+ */
77
+ merge: (value: Partial<Value>) => void;
78
+ /**
79
+ * Change only one key of the atom
80
+ * Works only if atom's value is an object
81
+ */
82
+ change: <T extends keyof Value>(key: T, newValue: any) => void;
83
+ /**
84
+ * Change only one key of the atom without triggering the update event
85
+ * Works only if atom's value is an object
86
+ */
87
+ silentChange: <T extends keyof Value>(key: T, newValue: any) => void;
88
+ /**
89
+ * Get current value
90
+ */
91
+ readonly value: Value;
92
+ /**
93
+ * Get default value that started with atom creation
94
+ */
95
+ readonly defaultValue: Value;
96
+ /**
97
+ * Destroy the atom and remove it from atmos list
98
+ * This will trigger an atom destroy event then unsubscribe all atom events
99
+ */
100
+ destroy: () => void;
101
+ /**
102
+ * An event listener to the atom value change
103
+ * The callback accepts the new updated value, the old value and an atom instance
104
+ */
105
+ onChange: (callback: AtomChangeCallback<Value, Actions>) => EventSubscription;
106
+ /**
107
+ * Watch for atom value change
108
+ * This can be used only when atom's default value is an object or an array
109
+ * The key accepts dot.notation syntax
110
+ */
111
+ watch: <T extends keyof Value>(key: T, callback: AtomPartialChangeCallback) => EventSubscription;
112
+ /**
113
+ * An event listener to the atom destruction
114
+ */
115
+ onDestroy(callback: (atom: Atom<Value>) => void): EventSubscription;
116
+ /**
117
+ * Called when reset is called
118
+ */
119
+ onReset(callback: (atom: Atom<Value>) => void): EventSubscription;
120
+ /**
121
+ * Get value from atom's value
122
+ * Works only if atom's value is an object
123
+ */
124
+ get<T extends keyof Value>(key: T, defaultValue?: any): Value[T];
125
+ /**
126
+ * Clone the atom
127
+ * This will return a new atom but the key will be suffixed with Clone{Number}
128
+ * i.e atom name is: user5122
129
+ * cloned atom name will be: userClone
130
+ */
131
+ clone: () => Atom<Value, Actions>;
132
+ /**
133
+ * Get the atom's value type
134
+ */
135
+ readonly type: string;
136
+ /**
137
+ * Get the atom's value length
138
+ *
139
+ * Works only if atom's value is an array or a string
140
+ */
141
+ readonly length: number;
142
+ } & Actions;
143
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD,MAAM,MAAM,yBAAyB,GAAG,CAAC,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;AAEhG,MAAM,MAAM,SAAS,CAAC,KAAK,IAAI,KAAK,CAAC;AAErC,MAAM,MAAM,gBAAgB,CAAC,KAAK,IAAI,CACpC,GAAG,IAAI,EAAE,GAAG,EAAE,KACX,IAAI,GAAG,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;AAEnD,MAAM,MAAM,WAAW,CAAC,KAAK,IAAI;IAC/B,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,GAAG,GAAG,CAAC;CACnE,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,KAAK,GAAG,GAAG,EAAE,OAAO,SAAS,WAAW,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI;IAC9E;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,OAAO,EAAE,KAAK,GAAG,OAAO,CAAC,KA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AAC;IAElE;;;OAGG;IACH,GAAG,CAAC,CAAC,SAAS,MAAM,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,YAAY,CAAC,EAAE,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IAEjE;;;;;OAKG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAElC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,GAAG,OAAO,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mongez/atom",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "An agnostic state management tool that work with any framework on browser or server",
5
5
  "main": "./cjs/index.js",
6
6
  "author": "hassanzohdy",