@slimlib/store 1.0.1 → 1.1.0
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 +100 -6
- package/core/package.json +3 -0
- package/dist/core.cjs +79 -0
- package/dist/core.d.ts +7 -0
- package/dist/core.mjs +75 -0
- package/dist/index.cjs +4 -74
- package/dist/index.d.ts +1 -7
- package/dist/index.mjs +1 -75
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/preact.cjs +18 -0
- package/dist/preact.d.ts +3 -0
- package/dist/preact.mjs +13 -0
- package/dist/preact.umd.js +2 -0
- package/dist/preact.umd.js.map +1 -0
- package/dist/react.cjs +18 -0
- package/dist/react.d.ts +3 -0
- package/dist/react.mjs +13 -0
- package/dist/react.umd.js +2 -0
- package/dist/react.umd.js.map +1 -0
- package/dist/svelte.cjs +9 -0
- package/dist/svelte.d.ts +1 -0
- package/dist/svelte.mjs +5 -0
- package/dist/svelte.umd.js +2 -0
- package/dist/svelte.umd.js.map +1 -0
- package/package.json +45 -5
- package/preact/package.json +3 -0
- package/react/package.json +3 -0
- package/svelte/package.json +3 -0
package/README.md
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Proxy-based store for SPAs.
|
|
4
4
|
|
|
5
|
+
1. Simple
|
|
6
|
+
2. Relatively fast
|
|
7
|
+
3. Small size (less than 1Kb minified not gzipped)
|
|
8
|
+
4. Typescript support
|
|
9
|
+
|
|
5
10
|
# Installation
|
|
6
11
|
|
|
7
12
|
Using npm:
|
|
@@ -11,19 +16,92 @@ npm install --save-dev @slimlib/store
|
|
|
11
16
|
|
|
12
17
|
# Usage
|
|
13
18
|
|
|
14
|
-
|
|
19
|
+
React:
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
import { createStore, useStore } from '@slimlib/store/react';
|
|
23
|
+
|
|
24
|
+
// create store
|
|
25
|
+
const [state, store] = createStore();
|
|
26
|
+
|
|
27
|
+
// action
|
|
28
|
+
function doSomething() {
|
|
29
|
+
state.field = value;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//component
|
|
33
|
+
function Component() {
|
|
34
|
+
const state = useStore(store);
|
|
35
|
+
|
|
36
|
+
// use state
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Preact:
|
|
41
|
+
|
|
42
|
+
```javascript
|
|
43
|
+
import { createStore, useStore } from '@slimlib/store/preact';
|
|
44
|
+
|
|
45
|
+
// create store
|
|
46
|
+
const [state, store] = createStore();
|
|
47
|
+
|
|
48
|
+
// action
|
|
49
|
+
function doSomething() {
|
|
50
|
+
state.field = value;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//component
|
|
54
|
+
function Component() {
|
|
55
|
+
const state = useStore(store);
|
|
56
|
+
|
|
57
|
+
// use state
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Svelte:
|
|
62
|
+
|
|
63
|
+
In store
|
|
64
|
+
|
|
65
|
+
```javascript
|
|
66
|
+
import { createStore, useStore } from '@slimlib/store/svelte';
|
|
67
|
+
|
|
68
|
+
// create store
|
|
69
|
+
const [state, store] = createStore();
|
|
70
|
+
|
|
71
|
+
// action
|
|
72
|
+
function doSomething() {
|
|
73
|
+
state.field = value;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export const storeName = {
|
|
77
|
+
subscribe: store
|
|
78
|
+
};
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
In component
|
|
82
|
+
|
|
83
|
+
```svelte
|
|
84
|
+
<script>
|
|
85
|
+
import { storeName } from './stores/storeName';
|
|
86
|
+
</script>
|
|
87
|
+
|
|
88
|
+
// use it in reactive way for reading data
|
|
89
|
+
$storeName
|
|
90
|
+
```
|
|
15
91
|
|
|
16
92
|
## API
|
|
17
93
|
|
|
18
|
-
###
|
|
94
|
+
### `main` and `core` exports
|
|
19
95
|
|
|
20
|
-
|
|
96
|
+
#### `createStoreFactory(notifyAfterCreation: boolean)`
|
|
21
97
|
|
|
22
|
-
|
|
98
|
+
The only exported function. It returns createStore factory (see next) which notifies innidiately after creating store if `notifyAfterCreation` is truethy.
|
|
99
|
+
|
|
100
|
+
#### `createStore<T>(initialState: T): [T, Store<T>]`
|
|
23
101
|
|
|
24
102
|
Store factory function that takes initial state and returns proxy object and store tuple. Proxy object ment to be left for actions implementations and store is for subscription for changes.
|
|
25
103
|
|
|
26
|
-
|
|
104
|
+
#### `Store<T>`
|
|
27
105
|
|
|
28
106
|
```typescript
|
|
29
107
|
type StoreCallback<T> = (value: T) => void;
|
|
@@ -36,6 +114,22 @@ interface Store<T> {
|
|
|
36
114
|
|
|
37
115
|
Publish/subscribe/read pattern implementation. Ment to be used in components / services that want to subscribe for store changes.
|
|
38
116
|
|
|
117
|
+
### `react` and `preact` exports
|
|
118
|
+
|
|
119
|
+
#### `createStore<T>(initialState: T): [T, Store<T>]`
|
|
120
|
+
|
|
121
|
+
Store factory created with `notifyAfterCreation` === `false`.
|
|
122
|
+
|
|
123
|
+
### `useStore<T>(store: Store<T>): Readonly<T>`
|
|
124
|
+
|
|
125
|
+
Function to subscribe to store inside component. Returns current state.
|
|
126
|
+
|
|
127
|
+
### `svelte` export
|
|
128
|
+
|
|
129
|
+
#### `createStore<T>(initialState: T): [T, Store<T>]`
|
|
130
|
+
|
|
131
|
+
Store factory created with `notifyAfterCreation` === `true`.
|
|
132
|
+
|
|
39
133
|
## Limitations
|
|
40
134
|
|
|
41
135
|
`Map`, `Set`, `WeakMap`, `WeakSet` cannot be used as values in current implementation.
|
|
@@ -45,4 +139,4 @@ Mixing proxied values and values from underlying object can fail for cases where
|
|
|
45
139
|
For example searching array element from underlying object in proxified array will fail.
|
|
46
140
|
# License
|
|
47
141
|
|
|
48
|
-
[MIT](./LICENSE)
|
|
142
|
+
[MIT](./LICENSE)
|
package/dist/core.cjs
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const unwrap = Symbol();
|
|
6
|
+
const unwrapValue = (value) => (value != null && value[unwrap]) || value;
|
|
7
|
+
const createStoreFactory = (notifyAfterCreation) => {
|
|
8
|
+
return (object = {}) => {
|
|
9
|
+
let willNotifyNextTick = false;
|
|
10
|
+
const proxiesCache = new WeakMap();
|
|
11
|
+
const storeListeners = new Set();
|
|
12
|
+
const enqueueNotification = () => {
|
|
13
|
+
if (!willNotifyNextTick) {
|
|
14
|
+
willNotifyNextTick = true;
|
|
15
|
+
queueMicrotask(() => {
|
|
16
|
+
willNotifyNextTick = false;
|
|
17
|
+
for (const listener of storeListeners) {
|
|
18
|
+
listener(object);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const handler = {
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
+
set(target, p, value, receiver) {
|
|
26
|
+
const realValue = unwrapValue(value);
|
|
27
|
+
if (Reflect.get(target, p, receiver) !== realValue) {
|
|
28
|
+
Reflect.set(target, p, realValue, receiver);
|
|
29
|
+
enqueueNotification();
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
},
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
|
+
get(target, p, receiver) {
|
|
35
|
+
if (p === unwrap)
|
|
36
|
+
return target;
|
|
37
|
+
const value = Reflect.get(target, p, receiver);
|
|
38
|
+
return value !== null && typeof value === 'object' && !(value instanceof RegExp) ? createProxy(value) : value;
|
|
39
|
+
},
|
|
40
|
+
defineProperty(...args) {
|
|
41
|
+
enqueueNotification();
|
|
42
|
+
return Reflect.defineProperty(...args);
|
|
43
|
+
},
|
|
44
|
+
deleteProperty(target, p) {
|
|
45
|
+
const result = Reflect.deleteProperty(target, p);
|
|
46
|
+
if (result) {
|
|
47
|
+
enqueueNotification();
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const proxy = createProxy(object);
|
|
53
|
+
return [
|
|
54
|
+
proxy,
|
|
55
|
+
((cb) => {
|
|
56
|
+
if (!cb) {
|
|
57
|
+
return object;
|
|
58
|
+
}
|
|
59
|
+
storeListeners.add(cb);
|
|
60
|
+
if (notifyAfterCreation) {
|
|
61
|
+
cb(object);
|
|
62
|
+
}
|
|
63
|
+
return () => storeListeners.delete(cb);
|
|
64
|
+
})
|
|
65
|
+
];
|
|
66
|
+
function createProxy(object) {
|
|
67
|
+
if (proxiesCache.has(object)) {
|
|
68
|
+
return proxiesCache.get(object);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
const proxy = new Proxy(object, handler);
|
|
72
|
+
proxiesCache.set(object, proxy);
|
|
73
|
+
return proxy;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
exports.createStoreFactory = createStoreFactory;
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare type StoreCallback<T> = (value: T) => void;
|
|
2
|
+
export declare type UnsubscribeCallback = () => void;
|
|
3
|
+
export interface Store<T> {
|
|
4
|
+
(cb: StoreCallback<T>): UnsubscribeCallback;
|
|
5
|
+
(): Readonly<T>;
|
|
6
|
+
}
|
|
7
|
+
export declare const createStoreFactory: (notifyAfterCreation: boolean) => <T extends object>(object?: T) => [T, Store<T>];
|
package/dist/core.mjs
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
];
|
|
62
|
+
function createProxy(object) {
|
|
63
|
+
if (proxiesCache.has(object)) {
|
|
64
|
+
return proxiesCache.get(object);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
const proxy = new Proxy(object, handler);
|
|
68
|
+
proxiesCache.set(object, proxy);
|
|
69
|
+
return proxy;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export { createStoreFactory };
|
package/dist/index.cjs
CHANGED
|
@@ -2,78 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
const unwrapValue = (value) => (value != null && value[unwrap]) || value;
|
|
7
|
-
const createStoreFactory = (notifyAfterCreation) => {
|
|
8
|
-
return (object = {}) => {
|
|
9
|
-
let willNotifyNextTick = false;
|
|
10
|
-
const proxiesCache = new WeakMap();
|
|
11
|
-
const storeListeners = new Set();
|
|
12
|
-
const enqueueNotification = () => {
|
|
13
|
-
if (!willNotifyNextTick) {
|
|
14
|
-
willNotifyNextTick = true;
|
|
15
|
-
queueMicrotask(() => {
|
|
16
|
-
willNotifyNextTick = false;
|
|
17
|
-
for (const listener of storeListeners) {
|
|
18
|
-
listener(object);
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
const handler = {
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
-
set(target, p, value, receiver) {
|
|
26
|
-
const realValue = unwrapValue(value);
|
|
27
|
-
if (Reflect.get(target, p, receiver) !== realValue) {
|
|
28
|
-
Reflect.set(target, p, realValue, receiver);
|
|
29
|
-
enqueueNotification();
|
|
30
|
-
}
|
|
31
|
-
return true;
|
|
32
|
-
},
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
|
-
get(target, p, receiver) {
|
|
35
|
-
if (p === unwrap)
|
|
36
|
-
return target;
|
|
37
|
-
const value = Reflect.get(target, p, receiver);
|
|
38
|
-
return value !== null && typeof value === 'object' && !(value instanceof RegExp) ? createProxy(value) : value;
|
|
39
|
-
},
|
|
40
|
-
defineProperty(...args) {
|
|
41
|
-
enqueueNotification();
|
|
42
|
-
return Reflect.defineProperty(...args);
|
|
43
|
-
},
|
|
44
|
-
deleteProperty(target, p) {
|
|
45
|
-
const result = Reflect.deleteProperty(target, p);
|
|
46
|
-
if (result) {
|
|
47
|
-
enqueueNotification();
|
|
48
|
-
}
|
|
49
|
-
return result;
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
const proxy = createProxy(object);
|
|
53
|
-
return [
|
|
54
|
-
proxy,
|
|
55
|
-
((cb) => {
|
|
56
|
-
if (!cb) {
|
|
57
|
-
return object;
|
|
58
|
-
}
|
|
59
|
-
storeListeners.add(cb);
|
|
60
|
-
if (notifyAfterCreation) {
|
|
61
|
-
cb(object);
|
|
62
|
-
}
|
|
63
|
-
return () => storeListeners.delete(cb);
|
|
64
|
-
})
|
|
65
|
-
];
|
|
66
|
-
function createProxy(object) {
|
|
67
|
-
if (proxiesCache.has(object)) {
|
|
68
|
-
return proxiesCache.get(object);
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
const proxy = new Proxy(object, handler);
|
|
72
|
-
proxiesCache.set(object, proxy);
|
|
73
|
-
return proxy;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
};
|
|
5
|
+
var core = require('./core.cjs');
|
|
78
6
|
|
|
79
|
-
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.createStoreFactory = core.createStoreFactory;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export declare type UnsubscribeCallback = () => void;
|
|
3
|
-
export interface Store<T> {
|
|
4
|
-
(cb: StoreCallback<T>): UnsubscribeCallback;
|
|
5
|
-
(): Readonly<T>;
|
|
6
|
-
}
|
|
7
|
-
export declare const createStoreFactory: (notifyAfterCreation: boolean) => <T extends object>(object?: T) => [T, Store<T>];
|
|
1
|
+
export * from './core';
|
package/dist/index.mjs
CHANGED
|
@@ -1,75 +1 @@
|
|
|
1
|
-
|
|
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
|
-
];
|
|
62
|
-
function createProxy(object) {
|
|
63
|
-
if (proxiesCache.has(object)) {
|
|
64
|
-
return proxiesCache.get(object);
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
const proxy = new Proxy(object, handler);
|
|
68
|
-
proxiesCache.set(object, proxy);
|
|
69
|
-
return proxy;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export { createStoreFactory };
|
|
1
|
+
export { createStoreFactory } from './core.mjs';
|
package/dist/index.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).slimlibStore={})}(this,(function(e){"use strict";
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("./core")):"function"==typeof define&&define.amd?define(["exports","./core"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).slimlibStore={},e.slimlibStoreCore)}(this,(function(e,t){"use strict";Object.keys(t).forEach((function(n){"default"===n||e.hasOwnProperty(n)||Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[n]}})})),Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
2
2
|
//# sourceMappingURL=index.umd.js.map
|
package/dist/index.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":[
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/preact.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var hooks = require('preact/hooks');
|
|
6
|
+
var core = require('./core.cjs');
|
|
7
|
+
|
|
8
|
+
const createStore = core.createStoreFactory(false);
|
|
9
|
+
const useStore = (store) => {
|
|
10
|
+
const [, setState] = hooks.useState();
|
|
11
|
+
hooks.useEffect(() => {
|
|
12
|
+
return store(() => setState({}));
|
|
13
|
+
}, []);
|
|
14
|
+
return store();
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
exports.createStore = createStore;
|
|
18
|
+
exports.useStore = useStore;
|
package/dist/preact.d.ts
ADDED
package/dist/preact.mjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useState, useEffect } from 'preact/hooks';
|
|
2
|
+
import { createStoreFactory } from './core.mjs';
|
|
3
|
+
|
|
4
|
+
const createStore = createStoreFactory(false);
|
|
5
|
+
const useStore = (store) => {
|
|
6
|
+
const [, setState] = useState();
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
return store(() => setState({}));
|
|
9
|
+
}, []);
|
|
10
|
+
return store();
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { createStore, useStore };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("preact/hooks"),require("./core")):"function"==typeof define&&define.amd?define(["exports","preact/hooks","./core"],o):o((e="undefined"!=typeof globalThis?globalThis:e||self).slimlibStorePreact={},e.preactHooks,e.slimlibStoreCore)}(this,(function(e,o,t){"use strict";const n=t.createStoreFactory(!1);e.createStore=n,e.useStore=e=>{const[,t]=o.useState();return o.useEffect((()=>e((()=>t({})))),[]),e()},Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
2
|
+
//# sourceMappingURL=preact.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preact.umd.js","sources":["../src/preact.ts"],"sourcesContent":["import { useState, useEffect } from 'preact/hooks';\nimport { createStoreFactory, Store } from './core';\n\nexport const createStore = createStoreFactory(false);\n\nexport const useStore = <T>(store: Store<T>) => {\n const [, setState] = useState<object>();\n \n useEffect(() => {\n return store(() => setState({}));\n }, []);\n \n return store();\n};\n"],"names":["createStore","createStoreFactory","store","setState","useState","useEffect"],"mappings":"uWAGaA,EAAcC,sBAAmB,8BAElBC,IACxB,OAASC,GAAYC,aAMrB,OAJAC,aAAU,IACCH,GAAM,IAAMC,EAAS,OAC7B,IAEID"}
|
package/dist/react.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var react = require('react');
|
|
6
|
+
var core = require('./core.cjs');
|
|
7
|
+
|
|
8
|
+
const createStore = core.createStoreFactory(false);
|
|
9
|
+
const useStore = (store) => {
|
|
10
|
+
const [, setState] = react.useState();
|
|
11
|
+
react.useEffect(() => {
|
|
12
|
+
return store(() => setState({}));
|
|
13
|
+
}, []);
|
|
14
|
+
return store();
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
exports.createStore = createStore;
|
|
18
|
+
exports.useStore = useStore;
|
package/dist/react.d.ts
ADDED
package/dist/react.mjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import { createStoreFactory } from './core.mjs';
|
|
3
|
+
|
|
4
|
+
const createStore = createStoreFactory(false);
|
|
5
|
+
const useStore = (store) => {
|
|
6
|
+
const [, setState] = useState();
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
return store(() => setState({}));
|
|
9
|
+
}, []);
|
|
10
|
+
return store();
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { createStore, useStore };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("./core")):"function"==typeof define&&define.amd?define(["exports","react","./core"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).slimlibStoreReact={},e.react,e.slimlibStoreCore)}(this,(function(e,t,o){"use strict";const n=o.createStoreFactory(!1);e.createStore=n,e.useStore=e=>{const[,o]=t.useState();return t.useEffect((()=>e((()=>o({})))),[]),e()},Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
2
|
+
//# sourceMappingURL=react.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.umd.js","sources":["../src/react.ts"],"sourcesContent":["import { useState, useEffect } from 'react';\nimport { createStoreFactory, Store } from './core';\n\nexport const createStore = createStoreFactory(false);\n\nexport const useStore = <T>(store: Store<T>) => {\n const [, setState] = useState<object>();\n \n useEffect(() => {\n return store(() => setState({}));\n }, []);\n \n return store();\n};\n"],"names":["createStore","createStoreFactory","store","setState","useState","useEffect"],"mappings":"kVAGaA,EAAcC,sBAAmB,8BAElBC,IACxB,OAASC,GAAYC,aAMrB,OAJAC,aAAU,IACCH,GAAM,IAAMC,EAAS,OAC7B,IAEID"}
|
package/dist/svelte.cjs
ADDED
package/dist/svelte.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createStore: <T extends object>(object?: T) => [T, import("./core").Store<T>];
|
package/dist/svelte.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("./core")):"function"==typeof define&&define.amd?define(["exports","./core"],o):o((e="undefined"!=typeof globalThis?globalThis:e||self).slimlibStoreSvelte={},e.slimlibStoreCore)}(this,(function(e,o){"use strict";const t=o.createStoreFactory(!0);e.createStore=t,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
2
|
+
//# sourceMappingURL=svelte.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svelte.umd.js","sources":["../src/svelte.ts"],"sourcesContent":["import { createStoreFactory } from './core';\n\nexport const createStore = createStoreFactory(true);\n"],"names":["createStore","createStoreFactory"],"mappings":"gTAEaA,EAAcC,sBAAmB"}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0
|
|
2
|
+
"version": "1.1.0",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "@slimlib/store",
|
|
5
5
|
"author": "Konstantin Shutkin",
|
|
@@ -8,6 +8,22 @@
|
|
|
8
8
|
".": {
|
|
9
9
|
"require": "./dist/index.cjs",
|
|
10
10
|
"default": "./dist/index.mjs"
|
|
11
|
+
},
|
|
12
|
+
"./core": {
|
|
13
|
+
"require": "./dist/core.cjs",
|
|
14
|
+
"default": "./dist/core.mjs"
|
|
15
|
+
},
|
|
16
|
+
"./react": {
|
|
17
|
+
"require": "./dist/react.cjs",
|
|
18
|
+
"default": "./dist/react.mjs"
|
|
19
|
+
},
|
|
20
|
+
"./preact": {
|
|
21
|
+
"require": "./dist/preact.cjs",
|
|
22
|
+
"default": "./dist/preact.mjs"
|
|
23
|
+
},
|
|
24
|
+
"./svelte": {
|
|
25
|
+
"require": "./dist/svelte.cjs",
|
|
26
|
+
"default": "./dist/svelte.mjs"
|
|
11
27
|
}
|
|
12
28
|
},
|
|
13
29
|
"main": "./dist/index.cjs",
|
|
@@ -15,7 +31,11 @@
|
|
|
15
31
|
"typings": "./dist/index.d.ts",
|
|
16
32
|
"unpkg": "./dist/index.umd.js",
|
|
17
33
|
"files": [
|
|
18
|
-
"dist"
|
|
34
|
+
"dist",
|
|
35
|
+
"react",
|
|
36
|
+
"preact",
|
|
37
|
+
"core",
|
|
38
|
+
"svelte"
|
|
19
39
|
],
|
|
20
40
|
"engines": {
|
|
21
41
|
"node": ">=15"
|
|
@@ -29,11 +49,23 @@
|
|
|
29
49
|
},
|
|
30
50
|
"homepage": "https://github.com/kshutkin/slimlib/store/README.md",
|
|
31
51
|
"scripts": {
|
|
32
|
-
"build": "pkgbld --umd=index",
|
|
52
|
+
"build": "pkgbld --umd=index,preact,react,svelte",
|
|
33
53
|
"test": "jest --collectCoverage",
|
|
34
54
|
"lint": "eslint ./src",
|
|
35
55
|
"semantic-release": "npx semantic-release"
|
|
36
56
|
},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"preact": ">=10.0.0",
|
|
59
|
+
"react": ">=17.0.0"
|
|
60
|
+
},
|
|
61
|
+
"peerDependenciesMeta": {
|
|
62
|
+
"react": {
|
|
63
|
+
"optional": true
|
|
64
|
+
},
|
|
65
|
+
"preact": {
|
|
66
|
+
"optional": true
|
|
67
|
+
}
|
|
68
|
+
},
|
|
37
69
|
"devDependencies": {
|
|
38
70
|
"@semantic-release/changelog": "6.0.1",
|
|
39
71
|
"@semantic-release/commit-analyzer": "9.0.2",
|
|
@@ -41,18 +73,26 @@
|
|
|
41
73
|
"@semantic-release/npm": "9.0.0",
|
|
42
74
|
"@semantic-release/release-notes-generator": "10.0.3",
|
|
43
75
|
"@types/jest": "27.4.0",
|
|
76
|
+
"@types/react": "^17.0.39",
|
|
44
77
|
"@typescript-eslint/eslint-plugin": "5.11.0",
|
|
45
78
|
"@typescript-eslint/parser": "5.11.0",
|
|
46
79
|
"conventional-changelog-angular": "5.0.13",
|
|
47
80
|
"eslint": "8.8.0",
|
|
48
81
|
"jest": "27.5.1",
|
|
82
|
+
"pkgbld": "1.1.9",
|
|
83
|
+
"preact": ">=10.0.0",
|
|
84
|
+
"react": ">=17.0.0",
|
|
85
|
+
"react-dom": ">=17.0.0",
|
|
86
|
+
"@testing-library/react": "12.1.3",
|
|
87
|
+
"@types/react-dom": ">=17.0.0",
|
|
49
88
|
"semantic-release": "19.0.2",
|
|
50
89
|
"semantic-release-monorepo": "7.0.5",
|
|
51
90
|
"ts-jest": "27.1.3",
|
|
52
91
|
"typescript": "4.5.x",
|
|
53
92
|
"update-monorepo-package-json": "0.2.0",
|
|
54
|
-
"
|
|
93
|
+
"@testing-library/svelte": "3.0.3",
|
|
94
|
+
"svelte": "3.46.4",
|
|
95
|
+
"svelte-jester": "2.3.2"
|
|
55
96
|
},
|
|
56
|
-
"dependencies": {},
|
|
57
97
|
"description": "Simple Proxy-based store for SPA"
|
|
58
98
|
}
|