svstate 1.0.0 → 1.0.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/README.md +2 -0
- package/dist/proxy.js +5 -5
- package/dist/state.svelte.js +2 -3
- package/dist/validators.js +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
[](https://nodejs.org/)
|
|
6
6
|
[](https://svelte.dev/)
|
|
7
7
|
[](https://opensource.org/licenses/ISC)
|
|
8
|
+
[]()
|
|
9
|
+
[]()
|
|
8
10
|
|
|
9
11
|
> **Deep reactive proxy with validation, snapshot/undo, and side effects — built for complex, real-world applications.**
|
|
10
12
|
|
package/dist/proxy.js
CHANGED
|
@@ -13,8 +13,8 @@ const isProxiable = (value) => typeof value === 'object' &&
|
|
|
13
13
|
!(value instanceof Promise);
|
|
14
14
|
const ChangeProxy = (source, changed) => {
|
|
15
15
|
const createProxy = (target, parentPath) => new Proxy(target, {
|
|
16
|
-
get(object, property
|
|
17
|
-
const value =
|
|
16
|
+
get(object, property) {
|
|
17
|
+
const value = object[property];
|
|
18
18
|
if (isProxiable(value)) {
|
|
19
19
|
const pathSegment = Number.isInteger(Number(property)) ? '' : String(property);
|
|
20
20
|
const childPath = pathSegment ? (parentPath ? `${parentPath}.${pathSegment}` : pathSegment) : parentPath;
|
|
@@ -22,10 +22,10 @@ const ChangeProxy = (source, changed) => {
|
|
|
22
22
|
}
|
|
23
23
|
return value;
|
|
24
24
|
},
|
|
25
|
-
set(object, property, incomingValue
|
|
26
|
-
const oldValue =
|
|
25
|
+
set(object, property, incomingValue) {
|
|
26
|
+
const oldValue = object[property];
|
|
27
27
|
if (oldValue !== incomingValue) {
|
|
28
|
-
|
|
28
|
+
object[property] = incomingValue;
|
|
29
29
|
const pathSegment = Number.isInteger(Number(property)) ? '' : String(property);
|
|
30
30
|
const fullPath = pathSegment ? (parentPath ? `${parentPath}.${pathSegment}` : pathSegment) : parentPath;
|
|
31
31
|
changed(data, fullPath, incomingValue, oldValue);
|
package/dist/state.svelte.js
CHANGED
|
@@ -13,9 +13,8 @@ const deepClone = (object) => {
|
|
|
13
13
|
if (Array.isArray(object))
|
|
14
14
|
return object.map((item) => deepClone(item));
|
|
15
15
|
const cloned = {};
|
|
16
|
-
for (const key
|
|
17
|
-
|
|
18
|
-
cloned[key] = deepClone(object[key]);
|
|
16
|
+
for (const key of Object.keys(object))
|
|
17
|
+
cloned[key] = deepClone(object[key]);
|
|
19
18
|
return cloned;
|
|
20
19
|
};
|
|
21
20
|
const defaultOptions = {
|
package/dist/validators.js
CHANGED
|
@@ -7,8 +7,8 @@ exports.dateValidator = dateValidator;
|
|
|
7
7
|
const prepareOps = {
|
|
8
8
|
trim: (s) => s.trim(),
|
|
9
9
|
normalize: (s) => s.replaceAll(/\s{2,}/g, ' '),
|
|
10
|
-
upper: (s) => s.
|
|
11
|
-
lower: (s) => s.
|
|
10
|
+
upper: (s) => s.toUpperCase(),
|
|
11
|
+
lower: (s) => s.toLowerCase()
|
|
12
12
|
};
|
|
13
13
|
function stringValidator(input, ...prepares) {
|
|
14
14
|
let error = '';
|
|
@@ -39,12 +39,12 @@ function stringValidator(input, ...prepares) {
|
|
|
39
39
|
return builder;
|
|
40
40
|
},
|
|
41
41
|
uppercase() {
|
|
42
|
-
if (!error && processedInput !== processedInput.
|
|
42
|
+
if (!error && processedInput !== processedInput.toUpperCase())
|
|
43
43
|
setError('Uppercase only');
|
|
44
44
|
return builder;
|
|
45
45
|
},
|
|
46
46
|
lowercase() {
|
|
47
|
-
if (!error && processedInput !== processedInput.
|
|
47
|
+
if (!error && processedInput !== processedInput.toLowerCase())
|
|
48
48
|
setError('Lowercase only');
|
|
49
49
|
return builder;
|
|
50
50
|
},
|
package/package.json
CHANGED