@slimlib/store 1.3.3 → 1.3.4
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/LICENSE +1 -1
- package/README.md +10 -8
- package/dist/core.cjs +73 -73
- package/dist/core.d.ts +8 -8
- package/dist/core.mjs +73 -73
- package/dist/index.d.ts +1 -1
- package/dist/preact.cjs +7 -7
- package/dist/preact.d.ts +3 -3
- package/dist/preact.mjs +7 -7
- package/dist/preact.umd.js.map +1 -1
- package/dist/react.cjs +7 -7
- package/dist/react.d.ts +3 -3
- package/dist/react.mjs +7 -7
- package/dist/react.umd.js.map +1 -1
- package/dist/svelte.d.ts +1 -1
- package/dist/svelte.umd.js.map +1 -1
- package/package.json +15 -31
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -7,6 +7,8 @@ Proxy-based store for SPAs.
|
|
|
7
7
|
3. Small size (less than 1Kb minified not gzipped)
|
|
8
8
|
4. Typescript support
|
|
9
9
|
|
|
10
|
+
[Changelog](./CHANGELOG.md)
|
|
11
|
+
|
|
10
12
|
# Installation
|
|
11
13
|
|
|
12
14
|
Using npm:
|
|
@@ -93,15 +95,15 @@ $storeName
|
|
|
93
95
|
|
|
94
96
|
#### `createStoreFactory(notifyAfterCreation: boolean)`
|
|
95
97
|
|
|
96
|
-
The only exported function. It returns createStore factory (see next) which notifies
|
|
98
|
+
The only exported function. It returns createStore factory (see next) which notifies immediately after creating store if `notifyAfterCreation` is truthy.
|
|
97
99
|
|
|
98
100
|
#### `createStore<T>(initialState: T): [T, Store<T>, () => void]`
|
|
99
101
|
|
|
100
|
-
Store factory function that takes initial state and returns proxy object, store and function to notify subscribers. Proxy object
|
|
102
|
+
Store factory function that takes initial state and returns proxy object, store and function to notify subscribers. Proxy object meant to be left for actions implementations, store is for subscription for changes and notification only for some edge cases when an original object has been changed and listeners have to be notified.
|
|
101
103
|
|
|
102
104
|
#### `unwrapValue(value: T): T`
|
|
103
105
|
|
|
104
|
-
Unwraps potential proxy object and returns plain object if possible or value itself.
|
|
106
|
+
Unwraps a potential proxy object and returns a plain object if possible or value itself.
|
|
105
107
|
|
|
106
108
|
#### `Store<T>`
|
|
107
109
|
|
|
@@ -114,7 +116,7 @@ interface Store<T> {
|
|
|
114
116
|
}
|
|
115
117
|
```
|
|
116
118
|
|
|
117
|
-
Publish/subscribe/read pattern implementation.
|
|
119
|
+
Publish/subscribe/read pattern implementation. Meant to be used in components / services that want to subscribe for store changes.
|
|
118
120
|
|
|
119
121
|
### `react` and `preact` exports
|
|
120
122
|
|
|
@@ -136,14 +138,14 @@ Store factory created with `notifyAfterCreation` === `true`.
|
|
|
136
138
|
|
|
137
139
|
`Map`, `Set`, `WeakMap`, `WeakSet` cannot be used as values in current implementation.
|
|
138
140
|
|
|
139
|
-
Mixing proxied values and values from underlying object can fail for cases where code needs checking for equality.
|
|
141
|
+
Mixing proxied values and values from an underlying object can fail for cases where code needs checking for equality.
|
|
140
142
|
|
|
141
|
-
For example searching array element from underlying object in proxified array will fail.
|
|
143
|
+
For example searching for an array element from the underlying object in a proxified array will fail.
|
|
142
144
|
|
|
143
145
|
## Similar projects
|
|
144
146
|
|
|
145
|
-
[Valtio](https://github.com/pmndrs/valtio) - more
|
|
147
|
+
[Valtio](https://github.com/pmndrs/valtio) - more sophisticated but similar approach, less limitations
|
|
146
148
|
|
|
147
149
|
# License
|
|
148
150
|
|
|
149
|
-
[MIT](
|
|
151
|
+
[MIT](https://github.com/kshutkin/slimlib/blob/main/LICENSE)
|
package/dist/core.cjs
CHANGED
|
@@ -1,78 +1,78 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const unwrap = Symbol();
|
|
4
|
-
const unwrapValue = (value) => (value != null && value[unwrap]) || value;
|
|
5
|
-
const createStoreFactory = (notifyAfterCreation) => {
|
|
6
|
-
return (object = {}) => {
|
|
7
|
-
let willNotifyNextTick = false;
|
|
8
|
-
const proxiesCache = new WeakMap();
|
|
9
|
-
const storeListeners = new Set();
|
|
10
|
-
const enqueueNotification = () => {
|
|
11
|
-
if (!willNotifyNextTick) {
|
|
12
|
-
willNotifyNextTick = true;
|
|
13
|
-
queueMicrotask(() => {
|
|
14
|
-
willNotifyNextTick = false;
|
|
15
|
-
for (const listener of storeListeners) {
|
|
16
|
-
listener(object);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
const handler = {
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
|
-
set(target, p, value, receiver) {
|
|
24
|
-
const realValue = unwrapValue(value);
|
|
25
|
-
if (Reflect.get(target, p, receiver) !== realValue) {
|
|
26
|
-
Reflect.set(target, p, realValue, receiver);
|
|
27
|
-
enqueueNotification();
|
|
28
|
-
}
|
|
29
|
-
return true;
|
|
30
|
-
},
|
|
31
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
|
-
get(target, p, receiver) {
|
|
33
|
-
if (p === unwrap)
|
|
34
|
-
return target;
|
|
35
|
-
const value = Reflect.get(target, p, receiver);
|
|
36
|
-
return value !== null && typeof value === 'object' && !(value instanceof RegExp) ? createProxy(value) : value;
|
|
37
|
-
},
|
|
38
|
-
defineProperty(...args) {
|
|
39
|
-
enqueueNotification();
|
|
40
|
-
return Reflect.defineProperty(...args);
|
|
41
|
-
},
|
|
42
|
-
deleteProperty(target, p) {
|
|
43
|
-
const result = Reflect.deleteProperty(target, p);
|
|
44
|
-
if (result) {
|
|
45
|
-
enqueueNotification();
|
|
46
|
-
}
|
|
47
|
-
return result;
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
const proxy = createProxy(object);
|
|
51
|
-
return [
|
|
52
|
-
proxy,
|
|
53
|
-
((cb) => {
|
|
54
|
-
if (!cb) {
|
|
55
|
-
return object;
|
|
56
|
-
}
|
|
57
|
-
storeListeners.add(cb);
|
|
58
|
-
if (notifyAfterCreation) {
|
|
59
|
-
cb(object);
|
|
60
|
-
}
|
|
61
|
-
return () => storeListeners.delete(cb);
|
|
62
|
-
}),
|
|
63
|
-
enqueueNotification
|
|
64
|
-
];
|
|
65
|
-
function createProxy(object) {
|
|
66
|
-
if (proxiesCache.has(object)) {
|
|
67
|
-
return proxiesCache.get(object);
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
const proxy = new Proxy(object, handler);
|
|
71
|
-
proxiesCache.set(object, proxy);
|
|
72
|
-
return proxy;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
};
|
|
3
|
+
const unwrap = Symbol();
|
|
4
|
+
const unwrapValue = (value) => (value != null && value[unwrap]) || value;
|
|
5
|
+
const createStoreFactory = (notifyAfterCreation) => {
|
|
6
|
+
return (object = {}) => {
|
|
7
|
+
let willNotifyNextTick = false;
|
|
8
|
+
const proxiesCache = new WeakMap();
|
|
9
|
+
const storeListeners = new Set();
|
|
10
|
+
const enqueueNotification = () => {
|
|
11
|
+
if (!willNotifyNextTick) {
|
|
12
|
+
willNotifyNextTick = true;
|
|
13
|
+
queueMicrotask(() => {
|
|
14
|
+
willNotifyNextTick = false;
|
|
15
|
+
for (const listener of storeListeners) {
|
|
16
|
+
listener(object);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const handler = {
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
|
+
set(target, p, value, receiver) {
|
|
24
|
+
const realValue = unwrapValue(value);
|
|
25
|
+
if (Reflect.get(target, p, receiver) !== realValue) {
|
|
26
|
+
Reflect.set(target, p, realValue, receiver);
|
|
27
|
+
enqueueNotification();
|
|
28
|
+
}
|
|
29
|
+
return true;
|
|
30
|
+
},
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
|
+
get(target, p, receiver) {
|
|
33
|
+
if (p === unwrap)
|
|
34
|
+
return target;
|
|
35
|
+
const value = Reflect.get(target, p, receiver);
|
|
36
|
+
return value !== null && typeof value === 'object' && !(value instanceof RegExp) ? createProxy(value) : value;
|
|
37
|
+
},
|
|
38
|
+
defineProperty(...args) {
|
|
39
|
+
enqueueNotification();
|
|
40
|
+
return Reflect.defineProperty(...args);
|
|
41
|
+
},
|
|
42
|
+
deleteProperty(target, p) {
|
|
43
|
+
const result = Reflect.deleteProperty(target, p);
|
|
44
|
+
if (result) {
|
|
45
|
+
enqueueNotification();
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const proxy = createProxy(object);
|
|
51
|
+
return [
|
|
52
|
+
proxy,
|
|
53
|
+
((cb) => {
|
|
54
|
+
if (!cb) {
|
|
55
|
+
return object;
|
|
56
|
+
}
|
|
57
|
+
storeListeners.add(cb);
|
|
58
|
+
if (notifyAfterCreation) {
|
|
59
|
+
cb(object);
|
|
60
|
+
}
|
|
61
|
+
return () => storeListeners.delete(cb);
|
|
62
|
+
}),
|
|
63
|
+
enqueueNotification
|
|
64
|
+
];
|
|
65
|
+
function createProxy(object) {
|
|
66
|
+
if (proxiesCache.has(object)) {
|
|
67
|
+
return proxiesCache.get(object);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
const proxy = new Proxy(object, handler);
|
|
71
|
+
proxiesCache.set(object, proxy);
|
|
72
|
+
return proxy;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
76
|
};
|
|
77
77
|
|
|
78
78
|
exports.createStoreFactory = createStoreFactory;
|
package/dist/core.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export interface Store<T> {
|
|
4
|
-
(cb: StoreCallback<T>): UnsubscribeCallback;
|
|
5
|
-
(): Readonly<T>;
|
|
6
|
-
}
|
|
7
|
-
export declare const unwrapValue: <T>(value: T) => T;
|
|
8
|
-
export declare const createStoreFactory: (notifyAfterCreation: boolean) => <T extends object>(object?: T) => [T, Store<T>, () => void];
|
|
1
|
+
export type StoreCallback<T> = (value: T) => void;
|
|
2
|
+
export type UnsubscribeCallback = () => void;
|
|
3
|
+
export interface Store<T> {
|
|
4
|
+
(cb: StoreCallback<T>): UnsubscribeCallback;
|
|
5
|
+
(): Readonly<T>;
|
|
6
|
+
}
|
|
7
|
+
export declare const unwrapValue: <T>(value: T) => T;
|
|
8
|
+
export declare const createStoreFactory: (notifyAfterCreation: boolean) => <T extends object>(object?: T) => [T, Store<T>, () => void];
|
package/dist/core.mjs
CHANGED
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
const unwrap = Symbol();
|
|
2
|
-
const unwrapValue = (value) => (value != null && value[unwrap]) || value;
|
|
3
|
-
const createStoreFactory = (notifyAfterCreation) => {
|
|
4
|
-
return (object = {}) => {
|
|
5
|
-
let willNotifyNextTick = false;
|
|
6
|
-
const proxiesCache = new WeakMap();
|
|
7
|
-
const storeListeners = new Set();
|
|
8
|
-
const enqueueNotification = () => {
|
|
9
|
-
if (!willNotifyNextTick) {
|
|
10
|
-
willNotifyNextTick = true;
|
|
11
|
-
queueMicrotask(() => {
|
|
12
|
-
willNotifyNextTick = false;
|
|
13
|
-
for (const listener of storeListeners) {
|
|
14
|
-
listener(object);
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
const handler = {
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
-
set(target, p, value, receiver) {
|
|
22
|
-
const realValue = unwrapValue(value);
|
|
23
|
-
if (Reflect.get(target, p, receiver) !== realValue) {
|
|
24
|
-
Reflect.set(target, p, realValue, receiver);
|
|
25
|
-
enqueueNotification();
|
|
26
|
-
}
|
|
27
|
-
return true;
|
|
28
|
-
},
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
-
get(target, p, receiver) {
|
|
31
|
-
if (p === unwrap)
|
|
32
|
-
return target;
|
|
33
|
-
const value = Reflect.get(target, p, receiver);
|
|
34
|
-
return value !== null && typeof value === 'object' && !(value instanceof RegExp) ? createProxy(value) : value;
|
|
35
|
-
},
|
|
36
|
-
defineProperty(...args) {
|
|
37
|
-
enqueueNotification();
|
|
38
|
-
return Reflect.defineProperty(...args);
|
|
39
|
-
},
|
|
40
|
-
deleteProperty(target, p) {
|
|
41
|
-
const result = Reflect.deleteProperty(target, p);
|
|
42
|
-
if (result) {
|
|
43
|
-
enqueueNotification();
|
|
44
|
-
}
|
|
45
|
-
return result;
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
const proxy = createProxy(object);
|
|
49
|
-
return [
|
|
50
|
-
proxy,
|
|
51
|
-
((cb) => {
|
|
52
|
-
if (!cb) {
|
|
53
|
-
return object;
|
|
54
|
-
}
|
|
55
|
-
storeListeners.add(cb);
|
|
56
|
-
if (notifyAfterCreation) {
|
|
57
|
-
cb(object);
|
|
58
|
-
}
|
|
59
|
-
return () => storeListeners.delete(cb);
|
|
60
|
-
}),
|
|
61
|
-
enqueueNotification
|
|
62
|
-
];
|
|
63
|
-
function createProxy(object) {
|
|
64
|
-
if (proxiesCache.has(object)) {
|
|
65
|
-
return proxiesCache.get(object);
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
const proxy = new Proxy(object, handler);
|
|
69
|
-
proxiesCache.set(object, proxy);
|
|
70
|
-
return proxy;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
};
|
|
1
|
+
const unwrap = Symbol();
|
|
2
|
+
const unwrapValue = (value) => (value != null && value[unwrap]) || value;
|
|
3
|
+
const createStoreFactory = (notifyAfterCreation) => {
|
|
4
|
+
return (object = {}) => {
|
|
5
|
+
let willNotifyNextTick = false;
|
|
6
|
+
const proxiesCache = new WeakMap();
|
|
7
|
+
const storeListeners = new Set();
|
|
8
|
+
const enqueueNotification = () => {
|
|
9
|
+
if (!willNotifyNextTick) {
|
|
10
|
+
willNotifyNextTick = true;
|
|
11
|
+
queueMicrotask(() => {
|
|
12
|
+
willNotifyNextTick = false;
|
|
13
|
+
for (const listener of storeListeners) {
|
|
14
|
+
listener(object);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const handler = {
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
+
set(target, p, value, receiver) {
|
|
22
|
+
const realValue = unwrapValue(value);
|
|
23
|
+
if (Reflect.get(target, p, receiver) !== realValue) {
|
|
24
|
+
Reflect.set(target, p, realValue, receiver);
|
|
25
|
+
enqueueNotification();
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
},
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
+
get(target, p, receiver) {
|
|
31
|
+
if (p === unwrap)
|
|
32
|
+
return target;
|
|
33
|
+
const value = Reflect.get(target, p, receiver);
|
|
34
|
+
return value !== null && typeof value === 'object' && !(value instanceof RegExp) ? createProxy(value) : value;
|
|
35
|
+
},
|
|
36
|
+
defineProperty(...args) {
|
|
37
|
+
enqueueNotification();
|
|
38
|
+
return Reflect.defineProperty(...args);
|
|
39
|
+
},
|
|
40
|
+
deleteProperty(target, p) {
|
|
41
|
+
const result = Reflect.deleteProperty(target, p);
|
|
42
|
+
if (result) {
|
|
43
|
+
enqueueNotification();
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const proxy = createProxy(object);
|
|
49
|
+
return [
|
|
50
|
+
proxy,
|
|
51
|
+
((cb) => {
|
|
52
|
+
if (!cb) {
|
|
53
|
+
return object;
|
|
54
|
+
}
|
|
55
|
+
storeListeners.add(cb);
|
|
56
|
+
if (notifyAfterCreation) {
|
|
57
|
+
cb(object);
|
|
58
|
+
}
|
|
59
|
+
return () => storeListeners.delete(cb);
|
|
60
|
+
}),
|
|
61
|
+
enqueueNotification
|
|
62
|
+
];
|
|
63
|
+
function createProxy(object) {
|
|
64
|
+
if (proxiesCache.has(object)) {
|
|
65
|
+
return proxiesCache.get(object);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
const proxy = new Proxy(object, handler);
|
|
69
|
+
proxiesCache.set(object, proxy);
|
|
70
|
+
return proxy;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
74
|
};
|
|
75
75
|
|
|
76
76
|
export { createStoreFactory, unwrapValue };
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './core';
|
|
1
|
+
export * from './core';
|
package/dist/preact.cjs
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
var hooks = require('preact/hooks');
|
|
4
4
|
var core = require('./core.cjs');
|
|
5
5
|
|
|
6
|
-
const createStore = core.createStoreFactory(false);
|
|
7
|
-
const useStore = (store) => {
|
|
8
|
-
const [, setState] = hooks.useState();
|
|
9
|
-
hooks.useEffect(() => {
|
|
10
|
-
return store(() => setState({}));
|
|
11
|
-
}, [store]);
|
|
12
|
-
return store();
|
|
6
|
+
const createStore = core.createStoreFactory(false);
|
|
7
|
+
const useStore = (store) => {
|
|
8
|
+
const [, setState] = hooks.useState();
|
|
9
|
+
hooks.useEffect(() => {
|
|
10
|
+
return store(() => setState({}));
|
|
11
|
+
}, [store]);
|
|
12
|
+
return store();
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
exports.createStore = createStore;
|
package/dist/preact.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Store } from './core';
|
|
2
|
-
export declare const createStore: <T extends object>(object?: T) => [T, Store<T>, () => void];
|
|
3
|
-
export declare const useStore: <T>(store: Store<T>) => Readonly<T>;
|
|
1
|
+
import { Store } from './core';
|
|
2
|
+
export declare const createStore: <T extends object>(object?: T) => [T, Store<T>, () => void];
|
|
3
|
+
export declare const useStore: <T>(store: Store<T>) => Readonly<T>;
|
package/dist/preact.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { useState, useEffect } from 'preact/hooks';
|
|
2
2
|
import { createStoreFactory } from './core.mjs';
|
|
3
3
|
|
|
4
|
-
const createStore = createStoreFactory(false);
|
|
5
|
-
const useStore = (store) => {
|
|
6
|
-
const [, setState] = useState();
|
|
7
|
-
useEffect(() => {
|
|
8
|
-
return store(() => setState({}));
|
|
9
|
-
}, [store]);
|
|
10
|
-
return store();
|
|
4
|
+
const createStore = createStoreFactory(false);
|
|
5
|
+
const useStore = (store) => {
|
|
6
|
+
const [, setState] = useState();
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
return store(() => setState({}));
|
|
9
|
+
}, [store]);
|
|
10
|
+
return store();
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
export { createStore, useStore };
|
package/dist/preact.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preact.umd.js","sources":[
|
|
1
|
+
{"version":3,"file":"preact.umd.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/react.cjs
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
var react = require('react');
|
|
4
4
|
var core = require('./core.cjs');
|
|
5
5
|
|
|
6
|
-
const createStore = core.createStoreFactory(false);
|
|
7
|
-
const useStore = (store) => {
|
|
8
|
-
const [, setState] = react.useState();
|
|
9
|
-
react.useEffect(() => {
|
|
10
|
-
return store(() => setState({}));
|
|
11
|
-
}, [store]);
|
|
12
|
-
return store();
|
|
6
|
+
const createStore = core.createStoreFactory(false);
|
|
7
|
+
const useStore = (store) => {
|
|
8
|
+
const [, setState] = react.useState();
|
|
9
|
+
react.useEffect(() => {
|
|
10
|
+
return store(() => setState({}));
|
|
11
|
+
}, [store]);
|
|
12
|
+
return store();
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
exports.createStore = createStore;
|
package/dist/react.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Store } from './core';
|
|
2
|
-
export declare const createStore: <T extends object>(object?: T) => [T, Store<T>, () => void];
|
|
3
|
-
export declare const useStore: <T>(store: Store<T>) => Readonly<T>;
|
|
1
|
+
import { Store } from './core';
|
|
2
|
+
export declare const createStore: <T extends object>(object?: T) => [T, Store<T>, () => void];
|
|
3
|
+
export declare const useStore: <T>(store: Store<T>) => Readonly<T>;
|
package/dist/react.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { useState, useEffect } from 'react';
|
|
2
2
|
import { createStoreFactory } from './core.mjs';
|
|
3
3
|
|
|
4
|
-
const createStore = createStoreFactory(false);
|
|
5
|
-
const useStore = (store) => {
|
|
6
|
-
const [, setState] = useState();
|
|
7
|
-
useEffect(() => {
|
|
8
|
-
return store(() => setState({}));
|
|
9
|
-
}, [store]);
|
|
10
|
-
return store();
|
|
4
|
+
const createStore = createStoreFactory(false);
|
|
5
|
+
const useStore = (store) => {
|
|
6
|
+
const [, setState] = useState();
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
return store(() => setState({}));
|
|
9
|
+
}, [store]);
|
|
10
|
+
return store();
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
export { createStore, useStore };
|
package/dist/react.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.umd.js","sources":[
|
|
1
|
+
{"version":3,"file":"react.umd.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/svelte.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const createStore: <T extends object>(object?: T) => [T, import("./core").Store<T>, () => void];
|
|
1
|
+
export declare const createStore: <T extends object>(object?: T) => [T, import("./core").Store<T>, () => void];
|
package/dist/svelte.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"svelte.umd.js","sources":[
|
|
1
|
+
{"version":3,"file":"svelte.umd.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.3.
|
|
2
|
+
"version": "1.3.4",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "@slimlib/store",
|
|
5
5
|
"author": "Konstantin Shutkin",
|
|
@@ -47,12 +47,6 @@
|
|
|
47
47
|
"url": "https://github.com/kshutkin/slimlib/issues"
|
|
48
48
|
},
|
|
49
49
|
"homepage": "https://github.com/kshutkin/slimlib/blob/main/store/README.md",
|
|
50
|
-
"scripts": {
|
|
51
|
-
"build": "pkgbld-internal --umd=index,preact,react,svelte",
|
|
52
|
-
"test": "jest --collectCoverage",
|
|
53
|
-
"lint": "eslint ./src",
|
|
54
|
-
"semantic-release": "npx semantic-release"
|
|
55
|
-
},
|
|
56
50
|
"peerDependencies": {
|
|
57
51
|
"preact": ">=10.0.0",
|
|
58
52
|
"react": ">=17.0.0"
|
|
@@ -66,37 +60,27 @@
|
|
|
66
60
|
}
|
|
67
61
|
},
|
|
68
62
|
"devDependencies": {
|
|
69
|
-
"@
|
|
70
|
-
"@semantic-release/commit-analyzer": "9.0.2",
|
|
71
|
-
"@semantic-release/git": "10.0.1",
|
|
72
|
-
"@semantic-release/npm": "9.0.0",
|
|
73
|
-
"@semantic-release/release-notes-generator": "10.0.3",
|
|
74
|
-
"@types/jest": "27.4.0",
|
|
75
|
-
"@types/react": "^17.0.39",
|
|
76
|
-
"@typescript-eslint/eslint-plugin": "5.11.0",
|
|
77
|
-
"@typescript-eslint/parser": "5.11.0",
|
|
78
|
-
"conventional-changelog-angular": "5.0.13",
|
|
79
|
-
"eslint": "8.8.0",
|
|
80
|
-
"jest": "27.5.1",
|
|
81
|
-
"pkgbld-internal": "1.0.8",
|
|
63
|
+
"@types/react": "^18.0.0",
|
|
82
64
|
"preact": ">=10.0.0",
|
|
83
65
|
"react": ">=17.0.0",
|
|
84
66
|
"react-dom": ">=17.0.0",
|
|
85
|
-
"@testing-library/react": "
|
|
67
|
+
"@testing-library/react": "^14.0.0",
|
|
86
68
|
"@types/react-dom": ">=17.0.0",
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"@testing-library/svelte": "3.0.3",
|
|
93
|
-
"svelte": "3.46.4",
|
|
94
|
-
"svelte-jester": "2.3.2"
|
|
69
|
+
"jest-environment-jsdom": "^29.4.3",
|
|
70
|
+
"@testing-library/svelte": "^3.2.2",
|
|
71
|
+
"svelte": "^3.55.1",
|
|
72
|
+
"svelte-jester": "^2.3.2",
|
|
73
|
+
"tslib": "^2.5.0"
|
|
95
74
|
},
|
|
96
75
|
"description": "Simple Proxy-based store for SPA",
|
|
97
76
|
"keywords": [
|
|
98
77
|
"@slimlib",
|
|
99
78
|
"store",
|
|
100
79
|
"proxy"
|
|
101
|
-
]
|
|
102
|
-
|
|
80
|
+
],
|
|
81
|
+
"scripts": {
|
|
82
|
+
"build": "pkgbld-internal --umd=index,preact,react,svelte",
|
|
83
|
+
"test": "jest --collectCoverage",
|
|
84
|
+
"lint": "eslint ./src"
|
|
85
|
+
}
|
|
86
|
+
}
|