ccstate 2.2.0 → 4.0.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/vue/index.js DELETED
@@ -1,66 +0,0 @@
1
- import { provide, inject, shallowRef, getCurrentInstance, onScopeDispose, shallowReadonly } from 'vue';
2
-
3
- var StoreKey = Symbol('ccstate-vue-store');
4
- var provideStore = function provideStore(store) {
5
- provide(StoreKey, store);
6
- };
7
- var useStore = function useStore() {
8
- var store = inject(StoreKey);
9
- if (store === undefined) {
10
- throw new Error('Store context not found - did you forget to wrap your app with StoreProvider?');
11
- }
12
- return store;
13
- };
14
-
15
- var globalId = 0;
16
- var generateToString = function generateToString(prefix, debugLabel) {
17
- var id = globalId++;
18
- var label = "".concat(prefix).concat(String(id)).concat('');
19
- return function () {
20
- return label;
21
- };
22
- };
23
- function command(write, options) {
24
- var ret = {
25
- write: write,
26
- toString: generateToString('F')
27
- };
28
- return ret;
29
- }
30
-
31
- function useGet(atom) {
32
- var store = useStore();
33
- var initialValue = store.get(atom);
34
- var vueState = shallowRef(initialValue);
35
- var controller = new AbortController();
36
- store.sub(atom, command(function () {
37
- var nextValue = store.get(atom);
38
- vueState.value = nextValue;
39
- }), {
40
- signal: controller.signal
41
- });
42
- if (getCurrentInstance()) {
43
- onScopeDispose(function () {
44
- controller.abort();
45
- });
46
- }
47
- return shallowReadonly(vueState);
48
- }
49
-
50
- function useSet(atom) {
51
- var store = useStore();
52
- if ('write' in atom) {
53
- return function () {
54
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
55
- args[_key] = arguments[_key];
56
- }
57
- var ret = store.set.apply(store, [atom].concat(args));
58
- return ret;
59
- };
60
- }
61
- return function (value) {
62
- store.set(atom, value);
63
- };
64
- }
65
-
66
- export { provideStore, useGet, useSet, useStore };