as-model 0.2.5 → 0.2.6

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/dist/index.js CHANGED
@@ -176,6 +176,9 @@ function modelStoreIdentifier() {
176
176
  function tokenIdentifier() {
177
177
  return true;
178
178
  }
179
+ function modelFieldIdentifier() {
180
+ return true;
181
+ }
179
182
 
180
183
  // src/validation/index.ts
181
184
  var noStateAModelKey = "no-state-a-model-key";
@@ -802,17 +805,22 @@ var cacheIdentify = {
802
805
  }
803
806
  };
804
807
  function wrapToField(cache, propertyName, value, onGot) {
805
- var cacheFields = cache.cacheFields;
806
- if (!cacheIdentify.field(value)) {
808
+ function collect(pName, v) {
807
809
  if (onGot) {
808
- onGot(propertyName, value);
810
+ onGot(pName, v);
809
811
  }
812
+ }
813
+ var cacheFields = cache.cacheFields;
814
+ if (!cacheIdentify.field(value)) {
815
+ collect(propertyName, value);
810
816
  return value;
811
817
  }
812
818
  var field2 = value;
813
819
  var cachedField = cacheFields[propertyName];
814
- if (cachedField) {
815
- return cachedField.getter;
820
+ if (cachedField && (field2.deps && shallowEqual(cachedField.deps, field2.deps) || !field2.deps && cachedField.value === field2.value)) {
821
+ var cacheFieldGetter = cachedField.getter;
822
+ collect(propertyName, cacheFieldGetter);
823
+ return cacheFieldGetter;
816
824
  }
817
825
  var getter = {
818
826
  get: function get() {
@@ -846,6 +854,7 @@ function wrapToField(cache, propertyName, value, onGot) {
846
854
  value: field2.value,
847
855
  deps: field2.deps
848
856
  };
857
+ collect(propertyName, getter);
849
858
  return getter;
850
859
  }
851
860
  function wrapToActionMethod(cache, methodName) {
@@ -987,6 +996,7 @@ function wrapToField2(updater, propertyName, value, onGot) {
987
996
  return cacheFieldGetter;
988
997
  }
989
998
  var getter = {
999
+ identifier: modelFieldIdentifier,
990
1000
  get: function get() {
991
1001
  var currentField = updater.instance[propertyName];
992
1002
  if (!cacheIdentify.field(currentField)) {
@@ -10,7 +10,11 @@ function modelStoreIdentifier() {
10
10
  function tokenIdentifier() {
11
11
  return true;
12
12
  }
13
+ function modelFieldIdentifier() {
14
+ return true;
15
+ }
13
16
  export {
17
+ modelFieldIdentifier,
14
18
  modelKeyIdentifier,
15
19
  modelStoreIdentifier,
16
20
  modelUsageIdentifier,
@@ -16,17 +16,22 @@ const cacheIdentify = {
16
16
  }
17
17
  };
18
18
  function wrapToField(cache, propertyName, value, onGot) {
19
- const { cacheFields } = cache;
20
- if (!cacheIdentify.field(value)) {
19
+ function collect(pName, v) {
21
20
  if (onGot) {
22
- onGot(propertyName, value);
21
+ onGot(pName, v);
23
22
  }
23
+ }
24
+ const { cacheFields } = cache;
25
+ if (!cacheIdentify.field(value)) {
26
+ collect(propertyName, value);
24
27
  return value;
25
28
  }
26
29
  const field = value;
27
30
  const cachedField = cacheFields[propertyName];
28
- if (cachedField) {
29
- return cachedField.getter;
31
+ if (cachedField && (field.deps && shallowEqual(cachedField.deps, field.deps) || !field.deps && cachedField.value === field.value)) {
32
+ const cacheFieldGetter = cachedField.getter;
33
+ collect(propertyName, cacheFieldGetter);
34
+ return cacheFieldGetter;
30
35
  }
31
36
  const getter = {
32
37
  get() {
@@ -56,6 +61,7 @@ function wrapToField(cache, propertyName, value, onGot) {
56
61
  }
57
62
  };
58
63
  cacheFields[propertyName] = { getter, value: field.value, deps: field.deps };
64
+ collect(propertyName, getter);
59
65
  return getter;
60
66
  }
61
67
  function wrapToActionMethod(cache, methodName) {
@@ -19,6 +19,7 @@ var __spreadValues = (a, b) => {
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
  import { createProxy, shallowEqual } from "../tools";
21
21
  import { defaultSelector } from "../defaults";
22
+ import { modelFieldIdentifier } from "../identifiers";
22
23
  import { cacheIdentify, cacheProperties } from "./cache";
23
24
  function createField(callback, deps) {
24
25
  const currentDeps = function computeDeps() {
@@ -102,6 +103,7 @@ function wrapToField(updater, propertyName, value, onGot) {
102
103
  return cacheFieldGetter;
103
104
  }
104
105
  const getter = {
106
+ identifier: modelFieldIdentifier,
105
107
  get() {
106
108
  const currentField = updater.instance[propertyName];
107
109
  if (!cacheIdentify.field(currentField)) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "as-model",
4
- "version": "0.2.5",
4
+ "version": "0.2.6",
5
5
  "description": "This is a model state management tool",
6
6
  "license": "MIT",
7
7
  "author": "Jimmy.Harding",