@slimlib/store 2.2.0 → 2.2.1

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.
Files changed (2) hide show
  1. package/index.mjs +14 -11
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -96,8 +96,12 @@ const makeNonLive = (node) => {
96
96
  };
97
97
 
98
98
  const clearSources = (node, fromIndex = 0) => {
99
- const isLive = (node.g & (8 | 64 )) !== 0;
100
99
  const nodeSources = node.h;
100
+
101
+ if ((node.g & (8 | 64 )) === 0) {
102
+ nodeSources.length = fromIndex;
103
+ return;
104
+ }
101
105
  for (let i = fromIndex, len = nodeSources.length; i < len; ++i) {
102
106
  const { c: c, d: sourceNode } = nodeSources[i];
103
107
 
@@ -109,8 +113,7 @@ const clearSources = (node, fromIndex = 0) => {
109
113
 
110
114
  c.delete(node);
111
115
 
112
- if (isLive &&
113
- sourceNode !== undefined &&
116
+ if (sourceNode !== undefined &&
114
117
  (sourceNode.g & (8 | 64 )) === 64 &&
115
118
  sourceNode.i.size === 0) {
116
119
  makeNonLive(sourceNode);
@@ -134,7 +137,7 @@ const flushEffects = () => {
134
137
  for (let i = 0, len = nodes.length; i < len; ++i) {
135
138
  const node = nodes[i];
136
139
  try {
137
- node.j?.();
140
+ node.j();
138
141
  }
139
142
  catch (e) {
140
143
  console.error(e);
@@ -149,7 +152,7 @@ const scheduleFlush = () => {
149
152
  }
150
153
  };
151
154
 
152
- const trackStateDependency = (deps, valueGetter, cachedValue) => {
155
+ const trackStateDependency = (deps, cachedValue) => {
153
156
 
154
157
  const sourcesArray = currentComputing.h;
155
158
  const skipIndex = currentComputing.k;
@@ -161,7 +164,7 @@ const trackStateDependency = (deps, valueGetter, cachedValue) => {
161
164
  clearSources(currentComputing, skipIndex);
162
165
  }
163
166
 
164
- sourcesArray.push(createSourceEntry(deps, undefined, deps.a, valueGetter, cachedValue));
167
+ sourcesArray.push(createSourceEntry(deps, undefined, deps.a, deps.b, cachedValue));
165
168
 
166
169
  currentComputing.g |= 128 ;
167
170
 
@@ -173,7 +176,6 @@ const trackStateDependency = (deps, valueGetter, cachedValue) => {
173
176
 
174
177
  const entry = sourcesArray[skipIndex];
175
178
  entry.a = deps.a;
176
- entry.b = valueGetter;
177
179
  entry.e = cachedValue;
178
180
 
179
181
  currentComputing.g |= 128 ;
@@ -696,7 +698,7 @@ function signal(initialValue) {
696
698
 
697
699
  if (tracked && currentComputing !== undefined) {
698
700
 
699
- trackStateDependency((deps ??= new DepsSet(read)), read, value);
701
+ trackStateDependency((deps ??= new DepsSet(read)), value);
700
702
  }
701
703
  return value;
702
704
 
@@ -730,8 +732,9 @@ function state(object = {}) {
730
732
  }
731
733
  };
732
734
  const createProxy = (object) => {
733
- if (proxiesCache.has(object)) {
734
- return proxiesCache.get(object);
735
+ const cachedProxy = proxiesCache.get(object);
736
+ if (cachedProxy !== undefined) {
737
+ return cachedProxy;
735
738
  }
736
739
  let methodCache;
737
740
  const proxy = new Proxy(object, {
@@ -772,7 +775,7 @@ function state(object = {}) {
772
775
  propsMap.set(p, (deps = new DepsSet(propertyGetter)));
773
776
  }
774
777
 
775
- trackStateDependency(deps, deps.b, propValue);
778
+ trackStateDependency(deps, propValue);
776
779
  }
777
780
 
778
781
  const propertyType = typeof propValue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "type": "module",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "name": "@slimlib/store",
5
5
  "description": "Simple Proxy-based store for SPA",
6
6
  "license": "MIT",