as-model 0.1.9 → 0.1.11

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.
@@ -1,69 +1,72 @@
1
- import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
2
- import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
3
- import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
4
20
  function defaultNotifyImplement(dispatches, action) {
5
- dispatches.forEach(function(callback) {
21
+ dispatches.forEach((callback) => {
6
22
  callback(action);
7
23
  });
8
24
  }
9
25
  function generateNotifier(updater, middleWare) {
10
26
  function pendAction(value) {
11
- updater.mutate(function(u) {
12
- var dispatching = u.dispatching;
27
+ updater.mutate((u) => {
28
+ const { dispatching } = u;
13
29
  if (!dispatching) {
14
- var wrap = {
15
- value
16
- };
30
+ const wrap = { value };
17
31
  wrap.tail = wrap;
18
- return _object_spread_props(_object_spread({}, u), {
19
- dispatching: wrap
20
- });
32
+ return __spreadProps(__spreadValues({}, u), { dispatching: wrap });
21
33
  }
22
- var tail = dispatching.tail;
34
+ const { tail } = dispatching;
23
35
  if (!tail) {
24
36
  return u;
25
37
  }
26
- var current = {
27
- prev: tail,
28
- value
29
- };
38
+ const current = { prev: tail, value };
30
39
  tail.next = current;
31
40
  dispatching.tail = current;
32
- return _object_spread_props(_object_spread({}, u), {
33
- dispatching
34
- });
41
+ return __spreadProps(__spreadValues({}, u), { dispatching });
35
42
  });
36
43
  }
37
44
  function unshiftAction() {
38
- return updater.mutate(function(u) {
39
- var dispatching = updater.dispatching;
45
+ return updater.mutate((u) => {
46
+ const { dispatching } = updater;
40
47
  if (!dispatching) {
41
48
  return u;
42
49
  }
43
- var next = dispatching.next, tail = dispatching.tail;
50
+ const { next, tail } = dispatching;
44
51
  if (tail === dispatching || !next) {
45
52
  dispatching.tail = void 0;
46
- return _object_spread_props(_object_spread({}, u), {
47
- dispatching: void 0
48
- });
53
+ return __spreadProps(__spreadValues({}, u), { dispatching: void 0 });
49
54
  }
50
55
  next.prev = void 0;
51
- var newFirst = next;
56
+ const newFirst = next;
52
57
  newFirst.tail = tail;
53
- return _object_spread_props(_object_spread({}, u), {
54
- dispatching: newFirst
55
- });
58
+ return __spreadProps(__spreadValues({}, u), { dispatching: newFirst });
56
59
  }).dispatching;
57
60
  }
58
61
  function consumeTemporaries() {
59
- var temporaryDispatches = updater.temporaryDispatches;
60
- updater.mutate(function(u) {
61
- return u.temporaryDispatches.length ? _object_spread_props(_object_spread({}, u), {
62
- dispatches: _to_consumable_array(u.dispatches).concat(_to_consumable_array(u.temporaryDispatches)),
62
+ const { temporaryDispatches } = updater;
63
+ updater.mutate(
64
+ (u) => u.temporaryDispatches.length ? __spreadProps(__spreadValues({}, u), {
65
+ dispatches: [...u.dispatches, ...u.temporaryDispatches],
63
66
  temporaryDispatches: []
64
- }) : u;
65
- });
66
- var initializedAction = {
67
+ }) : u
68
+ );
69
+ const initializedAction = {
67
70
  state: updater.state,
68
71
  prevState: updater.state,
69
72
  instance: updater.instance,
@@ -71,27 +74,23 @@ function generateNotifier(updater, middleWare) {
71
74
  type: null,
72
75
  method: null
73
76
  };
74
- temporaryDispatches.forEach(function(call) {
77
+ temporaryDispatches.forEach((call) => {
75
78
  call(initializedAction);
76
79
  });
77
80
  }
78
- var config = updater.config, model = updater.model;
79
- var dispatch = function dispatch2(action) {
80
- var dispatches = updater.dispatches, controlled = updater.controlled;
81
- var dispatchCallbacks = _to_consumable_array(dispatches);
82
- var state = action.state;
83
- var nextInstance = model(state);
84
- var nextAction = _object_spread_props(_object_spread({}, action), {
85
- instance: nextInstance
86
- });
81
+ const { config, model } = updater;
82
+ const dispatch = function dispatch2(action) {
83
+ const { dispatches, controlled } = updater;
84
+ const dispatchCallbacks = [...dispatches];
85
+ const { state } = action;
86
+ const nextInstance = model(state);
87
+ const nextAction = __spreadProps(__spreadValues({}, action), { instance: nextInstance });
87
88
  if (!controlled) {
88
- updater.mutate(function(u) {
89
- return _object_spread_props(_object_spread({}, u), {
90
- state,
91
- instance: nextInstance,
92
- version: u.version + 1
93
- });
94
- });
89
+ updater.mutate((u) => __spreadProps(__spreadValues({}, u), {
90
+ state,
91
+ instance: nextInstance,
92
+ version: u.version + 1
93
+ }));
95
94
  }
96
95
  try {
97
96
  if (typeof config.batchNotify === "function") {
@@ -100,11 +99,7 @@ function generateNotifier(updater, middleWare) {
100
99
  defaultNotifyImplement(dispatchCallbacks, nextAction);
101
100
  }
102
101
  } catch (e) {
103
- updater.mutate(function(u) {
104
- return _object_spread_props(_object_spread({}, u), {
105
- dispatching: void 0
106
- });
107
- });
102
+ updater.mutate((u) => __spreadProps(__spreadValues({}, u), { dispatching: void 0 }));
108
103
  throw e;
109
104
  }
110
105
  };
@@ -112,30 +107,23 @@ function generateNotifier(updater, middleWare) {
112
107
  if (action == null || updater.isDestroyed) {
113
108
  return;
114
109
  }
115
- var dispatching = updater.dispatching;
110
+ const { dispatching } = updater;
116
111
  pendAction(action);
117
112
  if (dispatching) {
118
113
  return;
119
114
  }
120
115
  while (updater.dispatching) {
121
- var wrap = updater.dispatching;
116
+ const wrap = updater.dispatching;
122
117
  if (wrap) {
123
118
  middleWare({
124
- getState: function getState() {
125
- return {
126
- state: updater.state,
127
- instance: updater.instance
128
- };
119
+ getState() {
120
+ return { state: updater.state, instance: updater.instance };
129
121
  },
130
122
  dispatch: notify
131
123
  })(dispatch)(wrap.value);
132
124
  unshiftAction();
133
125
  } else {
134
- updater.mutate(function(u) {
135
- return _object_spread_props(_object_spread({}, u), {
136
- dispatching: void 0
137
- });
138
- });
126
+ updater.mutate((u) => __spreadProps(__spreadValues({}, u), { dispatching: void 0 }));
139
127
  }
140
128
  }
141
129
  consumeTemporaries();
@@ -1,29 +1,43 @@
1
- import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
2
- import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
3
- import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
4
20
  import { noop } from "../tools";
5
21
  function createUnInitializedUpdater() {
6
22
  return {
7
- notify: function(a) {
23
+ notify: (a) => {
8
24
  },
9
- createTunnel: function(dispatcher) {
10
- return {
11
- connect: noop,
12
- disconnect: noop
13
- };
14
- }
25
+ createTunnel: (dispatcher) => ({
26
+ connect: noop,
27
+ disconnect: noop
28
+ })
15
29
  };
16
30
  }
17
31
  function destroy(updater) {
18
32
  function destroyDispatching() {
19
- updater.mutate(function(u) {
20
- var dispatching = u.dispatching;
33
+ updater.mutate((u) => {
34
+ const { dispatching } = u;
21
35
  if (!dispatching) {
22
36
  return u;
23
37
  }
24
- var wrapper = dispatching;
38
+ let wrapper = dispatching;
25
39
  while (wrapper) {
26
- var next = wrapper.next;
40
+ const { next } = wrapper;
27
41
  wrapper.next = void 0;
28
42
  wrapper.prev = void 0;
29
43
  if (next) {
@@ -32,58 +46,46 @@ function destroy(updater) {
32
46
  wrapper = next;
33
47
  }
34
48
  dispatching.tail = void 0;
35
- return _object_spread_props(_object_spread({}, u), {
36
- dispatching: void 0,
37
- initialized: false
38
- });
49
+ return __spreadProps(__spreadValues({}, u), { dispatching: void 0, initialized: false });
39
50
  });
40
51
  }
41
- updater.mutate(function(u, effect) {
42
- var destroyed = createUnInitializedUpdater();
43
- effect(function() {
52
+ updater.mutate((u, effect) => {
53
+ const destroyed = createUnInitializedUpdater();
54
+ effect(() => {
44
55
  destroyDispatching();
45
56
  });
46
- return _object_spread_props(_object_spread({}, u, destroyed), {
47
- sidePayload: void 0,
48
- isDestroyed: true
49
- });
57
+ return __spreadProps(__spreadValues(__spreadValues({}, u), destroyed), { sidePayload: void 0, isDestroyed: true });
50
58
  });
51
59
  }
52
60
  function generateTunnelCreator(updater) {
53
61
  function subscribe(dispatchFn) {
54
- var dispatches = updater.dispatches, temporaryDispatches = updater.temporaryDispatches, isControlled = updater.controlled;
55
- var copied = _to_consumable_array(dispatches).concat(_to_consumable_array(temporaryDispatches));
56
- var exist = copied.indexOf(dispatchFn) >= 0;
62
+ const {
63
+ dispatches,
64
+ temporaryDispatches,
65
+ controlled: isControlled
66
+ } = updater;
67
+ const copied = [...dispatches, ...temporaryDispatches];
68
+ const exist = copied.indexOf(dispatchFn) >= 0;
57
69
  if (exist) {
58
- return updater.mutate(function(u) {
59
- return _object_spread_props(_object_spread({}, u), {
60
- isDestroyed: false
61
- });
62
- });
70
+ return updater.mutate((u) => __spreadProps(__spreadValues({}, u), { isDestroyed: false }));
63
71
  }
64
72
  if (isControlled) {
65
- return updater.mutate(function(u) {
66
- return _object_spread_props(_object_spread({}, u), {
67
- dispatches: [
68
- dispatchFn
69
- ],
70
- isDestroyed: false
71
- });
72
- });
73
+ return updater.mutate((u) => __spreadProps(__spreadValues({}, u), {
74
+ dispatches: [dispatchFn],
75
+ isDestroyed: false
76
+ }));
73
77
  }
74
- return updater.mutate(function(u, effect) {
75
- var tds = u.temporaryDispatches, ds = u.dispatches;
76
- var nextTds = _to_consumable_array(tds).concat([
77
- dispatchFn
78
- ]);
78
+ return updater.mutate((u, effect) => {
79
+ const { temporaryDispatches: tds, dispatches: ds } = u;
80
+ const nextTds = [...tds, dispatchFn];
79
81
  if (u.dispatching) {
80
- return _object_spread_props(_object_spread({}, u), {
82
+ return __spreadProps(__spreadValues({}, u), {
81
83
  temporaryDispatches: nextTds,
82
84
  isDestroyed: false
83
85
  });
84
86
  }
85
- effect(function(up) {
86
- var initializedAction = {
87
+ effect((up) => {
88
+ const initializedAction = {
87
89
  state: up.state,
88
90
  prevState: up.state,
89
91
  instance: up.instance,
@@ -91,41 +93,37 @@ function generateTunnelCreator(updater) {
91
93
  type: null,
92
94
  method: null
93
95
  };
94
- nextTds.forEach(function(td) {
96
+ nextTds.forEach((td) => {
95
97
  td(initializedAction);
96
98
  });
97
99
  });
98
- return _object_spread_props(_object_spread({}, u), {
100
+ return __spreadProps(__spreadValues({}, u), {
99
101
  temporaryDispatches: [],
100
- dispatches: _to_consumable_array(ds).concat(_to_consumable_array(nextTds)),
102
+ dispatches: [...ds, ...nextTds],
101
103
  isDestroyed: false
102
104
  });
103
105
  });
104
106
  }
105
107
  return function tunnel(dispatcher) {
106
108
  function disconnect() {
107
- updater.mutate(function(u) {
108
- var ds = u.dispatches, tds = u.temporaryDispatches;
109
- var nextDs = ds.filter(function(d) {
110
- return d !== dispatcher;
111
- });
112
- var nextTds = tds.filter(function(d) {
113
- return d !== dispatcher;
114
- });
109
+ updater.mutate((u) => {
110
+ const { dispatches: ds, temporaryDispatches: tds } = u;
111
+ const nextDs = ds.filter((d) => d !== dispatcher);
112
+ const nextTds = tds.filter((d) => d !== dispatcher);
115
113
  if (ds.length === nextDs.length && tds.length === nextTds.length) {
116
114
  return u;
117
115
  }
118
- return _object_spread_props(_object_spread({}, u), {
116
+ return __spreadProps(__spreadValues({}, u), {
119
117
  dispatches: nextDs,
120
118
  temporaryDispatches: nextTds
121
119
  });
122
120
  });
123
121
  }
124
122
  return {
125
- connect: function connect() {
123
+ connect() {
126
124
  subscribe(dispatcher);
127
125
  },
128
- disconnect: function disconnect1() {
126
+ disconnect() {
129
127
  disconnect();
130
128
  }
131
129
  };
@@ -1,20 +1,20 @@
1
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
2
- import { _ as _type_of } from "@swc/helpers/_/_type_of";
3
1
  import { modelKeyIdentifier, modelStoreIdentifier, modelUsageIdentifier } from "../identifiers";
4
- var noStateAModelKey = "no-state-a-model-key";
2
+ const noStateAModelKey = "no-state-a-model-key";
5
3
  function createNoStateModel() {
6
4
  return function noStateModel(state) {
7
- return _define_property({}, noStateAModelKey, true);
5
+ return {
6
+ [noStateAModelKey]: true
7
+ };
8
8
  };
9
9
  }
10
10
  function isInstanceFromNoStateModel(instance) {
11
11
  if (instance == null) {
12
12
  return false;
13
13
  }
14
- if ((typeof instance === "undefined" ? "undefined" : _type_of(instance)) !== "object") {
14
+ if (typeof instance !== "object") {
15
15
  return false;
16
16
  }
17
- var ins = instance;
17
+ const ins = instance;
18
18
  return !!ins[noStateAModelKey];
19
19
  }
20
20
  function isModelKey(data) {
@@ -35,7 +35,7 @@ function isModelStore(data) {
35
35
  }
36
36
  return data.modelStoreIdentifier === modelStoreIdentifier && data.modelStoreIdentifier();
37
37
  }
38
- var validations = {
38
+ const validations = {
39
39
  isInstanceFromNoStateModel,
40
40
  isModelKey,
41
41
  isModelStore,
package/index.d.ts CHANGED
@@ -199,9 +199,7 @@ declare interface SignalStore<
199
199
  startStatistics: () => void;
200
200
  stopStatistics: () => void;
201
201
  subscribe: (dispatcher: Dispatch) => () => void;
202
- payload: <P>(
203
- callback?: (payload: P | undefined) => P | undefined
204
- ) => P | undefined;
202
+ store: Store<S, T, R>;
205
203
  };
206
204
  }
207
205
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "as-model",
4
- "version": "0.1.9",
4
+ "version": "0.1.11",
5
5
  "description": "This is a model state management tool",
6
6
  "license": "MIT",
7
7
  "author": "Jimmy.Harding",
package/esm/model/type.js DELETED
File without changes
package/esm/tools.js DELETED
@@ -1,78 +0,0 @@
1
- import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
2
- import { _ as _type_of } from "@swc/helpers/_/_type_of";
3
- function getDescriptors(target, receiver, ownOrPrototype, handler) {
4
- var it = Object.keys(ownOrPrototype);
5
- var result = {};
6
- it.forEach(function(key) {
7
- result[key] = {
8
- get: function() {
9
- if (!handler.get) {
10
- return target[key];
11
- }
12
- return handler.get(target, key, receiver);
13
- },
14
- set: function(v) {
15
- if (!handler.set) {
16
- target[key] = v;
17
- return;
18
- }
19
- var valid = handler.set(target, key, v, receiver);
20
- if (!valid) {
21
- throw new Error("".concat(key, " in proxy target is not mutable"));
22
- }
23
- }
24
- };
25
- });
26
- return result;
27
- }
28
- var createSimpleProxy = function(target, handler) {
29
- var proxy = {};
30
- var own = getDescriptors(target, proxy, target, handler);
31
- var prototype = getDescriptors(target, proxy, Object.getPrototypeOf(target), handler);
32
- Object.defineProperties(proxy, _object_spread({}, prototype, own));
33
- return proxy;
34
- };
35
- var createProxy = function(target, handler) {
36
- if (typeof Proxy !== "function") {
37
- return createSimpleProxy(target, handler);
38
- }
39
- return new Proxy(target, handler);
40
- };
41
- function isObject(data) {
42
- return data && (typeof data === "undefined" ? "undefined" : _type_of(data)) === "object";
43
- }
44
- function shallowEqual(prev, current) {
45
- if (Object.is(prev, current)) {
46
- return true;
47
- }
48
- if (!isObject(prev) || !isObject(current)) {
49
- return false;
50
- }
51
- var prevKeys = Object.keys(prev);
52
- var currentKeys = Object.keys(current);
53
- if (prevKeys.length !== currentKeys.length) {
54
- return false;
55
- }
56
- var pre = prev;
57
- var curr = current;
58
- var hasDiffKey = prevKeys.some(function(key) {
59
- return !Object.prototype.hasOwnProperty.call(curr, key);
60
- });
61
- if (hasDiffKey) {
62
- return false;
63
- }
64
- var hasDiffValue = currentKeys.some(function(key) {
65
- var currentValue = curr[key];
66
- var prevValue = pre[key];
67
- return !Object.is(currentValue, prevValue);
68
- });
69
- return !hasDiffValue;
70
- }
71
- function noop() {
72
- }
73
- export {
74
- createProxy,
75
- createSimpleProxy,
76
- noop,
77
- shallowEqual
78
- };