@vanyamate/sec 0.2.0 → 0.2.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.
package/README.md CHANGED
@@ -46,7 +46,7 @@ const loginAction = async function (loginData: LoginData): Promise<UserData> {
46
46
  const loginEffect = effect(loginAction);
47
47
 
48
48
  // Anywhere in code
49
- loginEffect();
49
+ loginEffect({ login: 'VanyaMate', password: 'qwerty12345' });
50
50
 
51
51
  ```
52
52
 
@@ -68,6 +68,8 @@ const logoutMarker = marker('afterAll').on('onSuccess', logoutEffect);
68
68
 
69
69
  ```
70
70
 
71
+ order of execution: 'beforeAll' -> undefined -> 'afterAll' (within one type (for example `onSuccess`))
72
+
71
73
  ### to
72
74
 
73
75
  Just helper. Returns a function that returns the passed value.
@@ -78,10 +80,33 @@ to(123); // Return () => 123
78
80
 
79
81
  ```
80
82
 
83
+ ```typescript
84
+ // before .on(logoutEffect, 'onSuccess', () => []);
85
+ // after .on(logoutEffect, 'onSuccess', to([]));
86
+ ```
87
+
81
88
  ### pending
82
89
 
83
90
  Just helper. wrapper over store. returns a bool value and is used to create a pending-store.
84
91
 
92
+ ```typescript
93
+ /**
94
+ *
95
+ * instead of
96
+ * const postsIsPending = store<boolean>(false)
97
+ * .on(getPostsForUser, 'onBefore', () => true)
98
+ * .on(getPostsForUser, 'onFinally', () => false)
99
+ * .on(createPostEffect, 'onBefore', () => true)
100
+ * .on(createPostEffect, 'onFinally', () => false);
101
+ *
102
+ */
103
+
104
+ const postsIsPending = pending([
105
+ getPostsForUser,
106
+ createPostEffect,
107
+ ]);
108
+ ```
109
+
85
110
  ### store
86
111
 
87
112
  Store stores data and subscribes to effect.
@@ -172,21 +197,29 @@ const posts = store<Array<Post>>([])
172
197
 
173
198
  ### Types
174
199
 
175
- instead of writing everything in `.on` - you can take out the handlers separately, setting the required type for them. `StoreEffectEventMap` is a generic and takes 2 parameters, and then the type is selected.
200
+ #### StoreHandlerMap
201
+
202
+ instead of writing everything in `.on` - you can take out the handlers separately, setting the required type for them.
203
+ `StoreHandlerMap` is a generic and takes 2 parameters, and then the type is selected.
204
+ first is type of store value. second is action signature. and then select type of subscribe.
205
+
206
+ ```
207
+ StoreHandlerMap<number, typeof getRandomId>['onSuccess']
208
+ ```
176
209
 
177
210
  ```typescript
178
211
  // Example:
179
212
 
180
213
  const getRandomId = async function () {
181
- return { id: Math.random() };
214
+ return { id: Math.random() };
182
215
  };
183
216
 
184
217
  const getRandomEffect = effect(getRandomId);
185
218
 
186
219
  const handler: StoreHandlerMap<number, typeof getRandomId>['onSuccess'] = function (state, { result }) {
187
- return result.id;
220
+ return result.id;
188
221
  };
189
222
 
190
223
  const num = store<number>(0)
191
- .on(getRandomEffect, 'onSuccess', handler);
224
+ .on(getRandomEffect, 'onSuccess', handler);
192
225
  ```
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=function(s,o){s&&o()},A=function(s,o=!0){const c={on:(n,f,t)=>(f==="onBefore"?n.onBefore((...e)=>u(o,()=>s=t(s,{args:e}))):f==="onSuccess"?n.onSuccess((e,...r)=>u(o,()=>s=t(s,{result:e,args:r}))):f==="onError"?n.onError((e,...r)=>u(o,()=>s=t(s,{error:e,args:r}))):n.onFinally((...e)=>u(o,()=>s=t(s,{args:e}))),c),get(){return s},set(n){s=n},subscribe(n){return()=>{}},enableOn(n){return n.subscribe(()=>o=!1),c},disableOn(n){return n.subscribe(()=>()=>o=!0),c}};return c},h=function(){return{afterAll:[],beforeAll:[],other:[]}},E=function(s){const o=h(),c=h(),n=h(),f=h(),t=async function(...e){return o.beforeAll.forEach(r=>r(...e)),o.other.forEach(r=>r(...e)),o.afterAll.forEach(r=>r(...e)),s(...e).then(r=>(c.beforeAll.forEach(l=>l(r,...e)),c.other.forEach(l=>l(r,...e)),c.afterAll.forEach(l=>l(r,...e)),r)).catch(r=>{throw n.beforeAll.forEach(l=>l(r,...e)),n.other.forEach(l=>l(r,...e)),n.afterAll.forEach(l=>l(r,...e)),r}).finally(()=>{f.beforeAll.forEach(r=>r(...e)),f.other.forEach(r=>r(...e)),f.afterAll.forEach(r=>r(...e))})};return t.onBefore=(e,r)=>{switch(r){case"beforeAll":o.beforeAll.push(e);break;case"afterAll":o.afterAll.push(e);break;default:o.other.push(e)}},t.onSuccess=(e,r)=>{switch(r){case"beforeAll":c.beforeAll.push(e);break;case"afterAll":c.afterAll.push(e);break;default:c.other.push(e)}},t.onError=(e,r)=>{switch(r){case"beforeAll":n.beforeAll.push(e);break;case"afterAll":n.afterAll.push(e);break;default:n.other.push(e)}},t.onFinally=(e,r)=>{switch(r){case"beforeAll":f.beforeAll.push(e);break;case"afterAll":f.afterAll.push(e);break;default:f.other.push(e)}},t},i=function(s,o,c=!0){let n=o(...s);const f=[];s.forEach(e=>{e.subscribe(()=>{u(c,()=>{n=o(...s),f.forEach(r=>r(n))})})});const t={on:()=>{throw new Error("Cannot call 'on' on combined store")},get(){return n},set(){throw new Error("Cannot call 'set' on combined store")},subscribe(e){return f.push(e),()=>{const r=f.indexOf(e);~r&&f.splice(r,1)}},enableOn(e){return e.subscribe(()=>c=!1),t},disableOn(e){return e.subscribe(()=>c=!0),t}};return t},a=function(s){const o=[],c={on:(n,f)=>(n==="onBefore"?f.onBefore(()=>o.forEach(t=>t()),s):n==="onSuccess"?f.onSuccess(()=>o.forEach(t=>t()),s):n==="onError"?f.onError(()=>o.forEach(t=>t()),s):f.onFinally(()=>o.forEach(t=>t()),s),c),subscribe:n=>{o.push(n)}};return c},b=function(s){return()=>s},p=function(s){const o=A(!1);return s.forEach(c=>{o.on(c,"onBefore",b(!0)),o.on(c,"onFinally",b(!1))}),o};exports.combine=i;exports.effect=E;exports.enableCheck=u;exports.marker=a;exports.pending=p;exports.store=A;exports.to=b;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=function(o,c){o&&c()},b=function(o,c=!0){const f=[],t={on:(n,s,e)=>(s==="onBefore"?n.onBefore((...r)=>u(c,()=>{o=e(o,{args:r}),f.forEach(l=>l(o))})):s==="onSuccess"?n.onSuccess((r,...l)=>u(c,()=>{o=e(o,{result:r,args:l}),f.forEach(i=>i(o))})):s==="onError"?n.onError((r,...l)=>u(c,()=>{o=e(o,{error:r,args:l}),f.forEach(i=>i(o))})):n.onFinally((...r)=>u(c,()=>o=e(o,{args:r}))),t),get(){return o},set(n){o=n},subscribe(n){return f.push(n),()=>{const s=f.indexOf(n);~s&&f.splice(s,1)}},enableOn(n){return n.subscribe(()=>c=!0),t},disableOn(n){return n.subscribe(()=>c=!1),t}};return t},h=function(){return{afterAll:[],beforeAll:[],other:[]}},A=function(o){const c=h(),f=h(),t=h(),n=h(),s=async function(...e){return c.beforeAll.forEach(r=>r(...e)),c.other.forEach(r=>r(...e)),c.afterAll.forEach(r=>r(...e)),o(...e).then(r=>(f.beforeAll.forEach(l=>l(r,...e)),f.other.forEach(l=>l(r,...e)),f.afterAll.forEach(l=>l(r,...e)),r)).catch(r=>{throw t.beforeAll.forEach(l=>l(r,...e)),t.other.forEach(l=>l(r,...e)),t.afterAll.forEach(l=>l(r,...e)),r}).finally(()=>{n.beforeAll.forEach(r=>r(...e)),n.other.forEach(r=>r(...e)),n.afterAll.forEach(r=>r(...e))})};return s.onBefore=(e,r)=>{switch(r){case"beforeAll":c.beforeAll.push(e);break;case"afterAll":c.afterAll.push(e);break;default:c.other.push(e)}},s.onSuccess=(e,r)=>{switch(r){case"beforeAll":f.beforeAll.push(e);break;case"afterAll":f.afterAll.push(e);break;default:f.other.push(e)}},s.onError=(e,r)=>{switch(r){case"beforeAll":t.beforeAll.push(e);break;case"afterAll":t.afterAll.push(e);break;default:t.other.push(e)}},s.onFinally=(e,r)=>{switch(r){case"beforeAll":n.beforeAll.push(e);break;case"afterAll":n.afterAll.push(e);break;default:n.other.push(e)}},s},E=function(o,c,f=!0){let t=c(...o);const n=[];o.forEach(e=>{e.subscribe(()=>{u(f,()=>{t=c(...o),n.forEach(r=>r(t))})})});const s={on:()=>{throw new Error("Cannot call 'on' on combined store")},get(){return t},set(){throw new Error("Cannot call 'set' on combined store")},subscribe(e){return n.push(e),()=>{const r=n.indexOf(e);~r&&n.splice(r,1)}},enableOn(e){return e.subscribe(()=>f=!1),s},disableOn(e){return e.subscribe(()=>f=!0),s}};return s},p=function(o){const c=[],f={on:(t,n)=>(t==="onBefore"?n.onBefore(()=>c.forEach(s=>s()),o):t==="onSuccess"?n.onSuccess(()=>c.forEach(s=>s()),o):t==="onError"?n.onError(()=>c.forEach(s=>s()),o):n.onFinally(()=>c.forEach(s=>s()),o),f),subscribe:t=>{c.push(t)}};return f},a=function(o){return()=>o},k=function(o){const c=b(!1);return o.forEach(f=>{c.on(f,"onBefore",a(!0)),c.on(f,"onFinally",a(!1))}),c};exports.combine=E;exports.effect=A;exports.enableCheck=u;exports.marker=p;exports.pending=k;exports.store=b;exports.to=a;
package/dist/index.d.ts CHANGED
@@ -50,7 +50,7 @@ export declare type Store<State> = {
50
50
  subscribe: (listener: StoreListener<State>) => () => void;
51
51
  };
52
52
 
53
- export declare const store: <State extends any>(initialData: State, enabled?: boolean) => Store<State>;
53
+ export declare const store: <State extends any>(state: State, enabled?: boolean) => Store<State>;
54
54
 
55
55
  export declare type StoreEffectSubscribe<State> = <Action extends EffectAction, Event extends keyof StoreHandlerMap<State, Action>>(effect: Effect<Action>, event: Event, handler: StoreHandlerMap<State, Action>[Event]) => Store<State>;
56
56
 
package/dist/index.js CHANGED
@@ -1,167 +1,175 @@
1
- const l = function(s, o) {
2
- s && o();
3
- }, A = function(s, o = !0) {
4
- const c = {
5
- on: (n, f, t) => (f === "onBefore" ? n.onBefore(
6
- (...e) => l(
7
- o,
8
- () => s = t(s, { args: e })
1
+ const u = function(o, c) {
2
+ o && c();
3
+ }, b = function(o, c = !0) {
4
+ const f = [], l = {
5
+ on: (n, s, r) => (s === "onBefore" ? n.onBefore(
6
+ (...e) => u(
7
+ c,
8
+ () => {
9
+ o = r(o, { args: e }), f.forEach((t) => t(o));
10
+ }
9
11
  )
10
- ) : f === "onSuccess" ? n.onSuccess(
11
- (e, ...r) => l(
12
- o,
13
- () => s = t(s, {
14
- result: e,
15
- args: r
16
- })
12
+ ) : s === "onSuccess" ? n.onSuccess(
13
+ (e, ...t) => u(
14
+ c,
15
+ () => {
16
+ o = r(o, {
17
+ result: e,
18
+ args: t
19
+ }), f.forEach((i) => i(o));
20
+ }
17
21
  )
18
- ) : f === "onError" ? n.onError(
19
- (e, ...r) => l(
20
- o,
21
- () => s = t(s, {
22
- error: e,
23
- args: r
24
- })
22
+ ) : s === "onError" ? n.onError(
23
+ (e, ...t) => u(
24
+ c,
25
+ () => {
26
+ o = r(o, {
27
+ error: e,
28
+ args: t
29
+ }), f.forEach((i) => i(o));
30
+ }
25
31
  )
26
32
  ) : n.onFinally(
27
- (...e) => l(
28
- o,
29
- () => s = t(s, { args: e })
33
+ (...e) => u(
34
+ c,
35
+ () => o = r(o, { args: e })
30
36
  )
31
- ), c),
37
+ ), l),
32
38
  get() {
33
- return s;
39
+ return o;
34
40
  },
35
41
  set(n) {
36
- s = n;
42
+ o = n;
37
43
  },
38
44
  subscribe(n) {
39
- return () => {
45
+ return f.push(n), () => {
46
+ const s = f.indexOf(n);
47
+ ~s && f.splice(s, 1);
40
48
  };
41
49
  },
42
50
  enableOn(n) {
43
- return n.subscribe(() => o = !1), c;
51
+ return n.subscribe(() => c = !0), l;
44
52
  },
45
53
  disableOn(n) {
46
- return n.subscribe(() => () => o = !0), c;
54
+ return n.subscribe(() => c = !1), l;
47
55
  }
48
56
  };
49
- return c;
57
+ return l;
50
58
  }, h = function() {
51
59
  return {
52
60
  afterAll: [],
53
61
  beforeAll: [],
54
62
  other: []
55
63
  };
56
- }, E = function(s) {
57
- const o = h(), c = h(), n = h(), f = h(), t = async function(...e) {
58
- return o.beforeAll.forEach((r) => r(...e)), o.other.forEach((r) => r(...e)), o.afterAll.forEach((r) => r(...e)), s(...e).then((r) => (c.beforeAll.forEach((u) => u(r, ...e)), c.other.forEach((u) => u(r, ...e)), c.afterAll.forEach((u) => u(r, ...e)), r)).catch((r) => {
59
- throw n.beforeAll.forEach((u) => u(r, ...e)), n.other.forEach((u) => u(r, ...e)), n.afterAll.forEach((u) => u(r, ...e)), r;
64
+ }, A = function(o) {
65
+ const c = h(), f = h(), l = h(), n = h(), s = async function(...r) {
66
+ return c.beforeAll.forEach((e) => e(...r)), c.other.forEach((e) => e(...r)), c.afterAll.forEach((e) => e(...r)), o(...r).then((e) => (f.beforeAll.forEach((t) => t(e, ...r)), f.other.forEach((t) => t(e, ...r)), f.afterAll.forEach((t) => t(e, ...r)), e)).catch((e) => {
67
+ throw l.beforeAll.forEach((t) => t(e, ...r)), l.other.forEach((t) => t(e, ...r)), l.afterAll.forEach((t) => t(e, ...r)), e;
60
68
  }).finally(() => {
61
- f.beforeAll.forEach((r) => r(...e)), f.other.forEach((r) => r(...e)), f.afterAll.forEach((r) => r(...e));
69
+ n.beforeAll.forEach((e) => e(...r)), n.other.forEach((e) => e(...r)), n.afterAll.forEach((e) => e(...r));
62
70
  });
63
71
  };
64
- return t.onBefore = (e, r) => {
65
- switch (r) {
72
+ return s.onBefore = (r, e) => {
73
+ switch (e) {
66
74
  case "beforeAll":
67
- o.beforeAll.push(e);
75
+ c.beforeAll.push(r);
68
76
  break;
69
77
  case "afterAll":
70
- o.afterAll.push(e);
78
+ c.afterAll.push(r);
71
79
  break;
72
80
  default:
73
- o.other.push(e);
81
+ c.other.push(r);
74
82
  }
75
- }, t.onSuccess = (e, r) => {
76
- switch (r) {
83
+ }, s.onSuccess = (r, e) => {
84
+ switch (e) {
77
85
  case "beforeAll":
78
- c.beforeAll.push(e);
86
+ f.beforeAll.push(r);
79
87
  break;
80
88
  case "afterAll":
81
- c.afterAll.push(e);
89
+ f.afterAll.push(r);
82
90
  break;
83
91
  default:
84
- c.other.push(e);
92
+ f.other.push(r);
85
93
  }
86
- }, t.onError = (e, r) => {
87
- switch (r) {
94
+ }, s.onError = (r, e) => {
95
+ switch (e) {
88
96
  case "beforeAll":
89
- n.beforeAll.push(e);
97
+ l.beforeAll.push(r);
90
98
  break;
91
99
  case "afterAll":
92
- n.afterAll.push(e);
100
+ l.afterAll.push(r);
93
101
  break;
94
102
  default:
95
- n.other.push(e);
103
+ l.other.push(r);
96
104
  }
97
- }, t.onFinally = (e, r) => {
98
- switch (r) {
105
+ }, s.onFinally = (r, e) => {
106
+ switch (e) {
99
107
  case "beforeAll":
100
- f.beforeAll.push(e);
108
+ n.beforeAll.push(r);
101
109
  break;
102
110
  case "afterAll":
103
- f.afterAll.push(e);
111
+ n.afterAll.push(r);
104
112
  break;
105
113
  default:
106
- f.other.push(e);
114
+ n.other.push(r);
107
115
  }
108
- }, t;
109
- }, a = function(s, o, c = !0) {
110
- let n = o(...s);
111
- const f = [];
112
- s.forEach((e) => {
113
- e.subscribe(() => {
114
- l(c, () => {
115
- n = o(...s), f.forEach((r) => r(n));
116
+ }, s;
117
+ }, E = function(o, c, f = !0) {
118
+ let l = c(...o);
119
+ const n = [];
120
+ o.forEach((r) => {
121
+ r.subscribe(() => {
122
+ u(f, () => {
123
+ l = c(...o), n.forEach((e) => e(l));
116
124
  });
117
125
  });
118
126
  });
119
- const t = {
127
+ const s = {
120
128
  on: () => {
121
129
  throw new Error("Cannot call 'on' on combined store");
122
130
  },
123
131
  get() {
124
- return n;
132
+ return l;
125
133
  },
126
134
  set() {
127
135
  throw new Error("Cannot call 'set' on combined store");
128
136
  },
129
- subscribe(e) {
130
- return f.push(e), () => {
131
- const r = f.indexOf(e);
132
- ~r && f.splice(r, 1);
137
+ subscribe(r) {
138
+ return n.push(r), () => {
139
+ const e = n.indexOf(r);
140
+ ~e && n.splice(e, 1);
133
141
  };
134
142
  },
135
- enableOn(e) {
136
- return e.subscribe(() => c = !1), t;
143
+ enableOn(r) {
144
+ return r.subscribe(() => f = !1), s;
137
145
  },
138
- disableOn(e) {
139
- return e.subscribe(() => c = !0), t;
146
+ disableOn(r) {
147
+ return r.subscribe(() => f = !0), s;
140
148
  }
141
149
  };
142
- return t;
143
- }, i = function(s) {
144
- const o = [], c = {
145
- on: (n, f) => (n === "onBefore" ? f.onBefore(() => o.forEach((t) => t()), s) : n === "onSuccess" ? f.onSuccess(() => o.forEach((t) => t()), s) : n === "onError" ? f.onError(() => o.forEach((t) => t()), s) : f.onFinally(() => o.forEach((t) => t()), s), c),
146
- subscribe: (n) => {
147
- o.push(n);
150
+ return s;
151
+ }, p = function(o) {
152
+ const c = [], f = {
153
+ on: (l, n) => (l === "onBefore" ? n.onBefore(() => c.forEach((s) => s()), o) : l === "onSuccess" ? n.onSuccess(() => c.forEach((s) => s()), o) : l === "onError" ? n.onError(() => c.forEach((s) => s()), o) : n.onFinally(() => c.forEach((s) => s()), o), f),
154
+ subscribe: (l) => {
155
+ c.push(l);
148
156
  }
149
157
  };
150
- return c;
151
- }, b = function(s) {
152
- return () => s;
153
- }, p = function(s) {
154
- const o = A(!1);
155
- return s.forEach((c) => {
156
- o.on(c, "onBefore", b(!0)), o.on(c, "onFinally", b(!1));
157
- }), o;
158
+ return f;
159
+ }, a = function(o) {
160
+ return () => o;
161
+ }, w = function(o) {
162
+ const c = b(!1);
163
+ return o.forEach((f) => {
164
+ c.on(f, "onBefore", a(!0)), c.on(f, "onFinally", a(!1));
165
+ }), c;
158
166
  };
159
167
  export {
160
- a as combine,
161
- E as effect,
162
- l as enableCheck,
163
- i as marker,
164
- p as pending,
165
- A as store,
166
- b as to
168
+ E as combine,
169
+ A as effect,
170
+ u as enableCheck,
171
+ p as marker,
172
+ w as pending,
173
+ b as store,
174
+ a as to
167
175
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vanyamate/sec",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "SEC. Store, Effect, Combine. Tiny state manager",
5
5
  "scripts": {
6
6
  "build": "vite build",
@@ -52,7 +52,7 @@ export const enableCheck = function (enabled: boolean, callback: () => void) {
52
52
  }
53
53
  };
54
54
 
55
- export const store = function <State extends any> (initialData: State, enabled: boolean = true): Store<State> {
55
+ export const store = function <State extends any> (state: State, enabled: boolean = true): Store<State> {
56
56
  const listeners: Array<StoreListener<State>> = [];
57
57
 
58
58
  const storeApi: Store<State> = {
@@ -64,32 +64,41 @@ export const store = function <State extends any> (initialData: State, enabled:
64
64
  effect.onBefore((...args) =>
65
65
  enableCheck(
66
66
  enabled,
67
- () => initialData = (handler as StoreOnBeforeHandler<State, Action>)(initialData, { args }),
67
+ () => {
68
+ state = (handler as StoreOnBeforeHandler<State, Action>)(state, { args });
69
+ listeners.forEach((listener) => listener(state));
70
+ },
68
71
  ),
69
72
  );
70
73
  } else if (event === 'onSuccess') {
71
74
  effect.onSuccess((result, ...args) =>
72
75
  enableCheck(
73
76
  enabled,
74
- () => initialData = (handler as StoreOnSuccessHandler<State, Action>)(initialData, {
75
- result, args,
76
- }),
77
+ () => {
78
+ state = (handler as StoreOnSuccessHandler<State, Action>)(state, {
79
+ result, args,
80
+ });
81
+ listeners.forEach((listener) => listener(state));
82
+ },
77
83
  ),
78
84
  );
79
85
  } else if (event === 'onError') {
80
86
  effect.onError((error, ...args) =>
81
87
  enableCheck(
82
88
  enabled,
83
- () => initialData = (handler as StoreOnErrorHandler<State, Action>)(initialData, {
84
- error, args,
85
- }),
89
+ () => {
90
+ state = (handler as StoreOnErrorHandler<State, Action>)(state, {
91
+ error, args,
92
+ });
93
+ listeners.forEach((listener) => listener(state));
94
+ },
86
95
  ),
87
96
  );
88
97
  } else {
89
98
  effect.onFinally((...args) =>
90
99
  enableCheck(
91
100
  enabled,
92
- () => initialData = (handler as StoreOnFinallyHandler<State, Action>)(initialData, { args }),
101
+ () => state = (handler as StoreOnFinallyHandler<State, Action>)(state, { args }),
93
102
  ),
94
103
  );
95
104
  }
@@ -97,10 +106,10 @@ export const store = function <State extends any> (initialData: State, enabled:
97
106
  return storeApi;
98
107
  },
99
108
  get (): State {
100
- return initialData;
109
+ return state;
101
110
  },
102
111
  set (value: State) {
103
- initialData = value;
112
+ state = value;
104
113
  },
105
114
  subscribe (listener: StoreListener<State>) {
106
115
  listeners.push(listener);
@@ -112,11 +121,11 @@ export const store = function <State extends any> (initialData: State, enabled:
112
121
  };
113
122
  },
114
123
  enableOn (marker: Marker<State>) {
115
- marker.subscribe(() => enabled = false);
124
+ marker.subscribe(() => enabled = true);
116
125
  return storeApi;
117
126
  },
118
127
  disableOn (marker: Marker<State>) {
119
- marker.subscribe(() => () => enabled = true);
128
+ marker.subscribe(() => enabled = false);
120
129
  return storeApi;
121
130
  },
122
131
  };