pawajs 1.5.1 → 1.5.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/CHANGELOG.md +2 -1
- package/index.js +39 -40
- package/package.json +1 -1
- package/reactive.js +11 -2
package/CHANGELOG.md
CHANGED
|
@@ -18,4 +18,5 @@ CHANGELOG.md
|
|
|
18
18
|
+ version 1.4.31- 1.4.32 - tried updating key to add element when server key is different
|
|
19
19
|
+ version 1.4.33 - added registerComponent.lazy
|
|
20
20
|
+ version 1.4.33 -1.4.42 fixing lazy registration component
|
|
21
|
-
+ version 1.5.1 stable
|
|
21
|
+
+ version 1.5.1 stable
|
|
22
|
+
+ version 1.5.2 - added function dependencies
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { track, trigger, createEffect } from './reactive.js'
|
|
1
|
+
import { track, trigger, createEffect, runWithEffect, deleteEffect } from './reactive.js'
|
|
2
2
|
import { PawaElement, PawaComment } from './pawaElement.js';
|
|
3
3
|
import {
|
|
4
4
|
If,
|
|
@@ -335,8 +335,10 @@ RegisterComponent.lazy=(...args)=>{
|
|
|
335
335
|
}
|
|
336
336
|
|
|
337
337
|
const processName =(compName) => {
|
|
338
|
+
if (__pawaDev.tool && isServer()) {
|
|
339
|
+
components.delete(compName.toUppercase())
|
|
340
|
+
}
|
|
338
341
|
if (components.has(compName.toUpperCase()) || lazyComponents.has(compName.toUpperCase()) && !__pawaDev.tool) return;
|
|
339
|
-
|
|
340
342
|
if (typeof compName === 'string') {
|
|
341
343
|
lazyComponents.set(compName.toUpperCase(), { name: compName, component: componentFunc });
|
|
342
344
|
}
|
|
@@ -764,17 +766,6 @@ export const $state = (initialValue, section = null) => {
|
|
|
764
766
|
localStorage.setItem(section, JSON.stringify(states))
|
|
765
767
|
}, 50)
|
|
766
768
|
}
|
|
767
|
-
globalEffectMap.forEach((effect) => {
|
|
768
|
-
|
|
769
|
-
if (effect.deps?.has(target.id)) {
|
|
770
|
-
if (effect.cleanup) {
|
|
771
|
-
effect.cleanup();
|
|
772
|
-
}
|
|
773
|
-
effect.cleanup = effect.callback();
|
|
774
|
-
} else if (effect.deps.size === 0) {
|
|
775
|
-
effect.cleanup = effect.callback();
|
|
776
|
-
}
|
|
777
|
-
});
|
|
778
769
|
});
|
|
779
770
|
if (Array.isArray(section)) {
|
|
780
771
|
if (stateContext._hasRun === false && typeof initialValue === 'function') {
|
|
@@ -816,47 +807,55 @@ const stateWatch = (callback, dependencies) => {
|
|
|
816
807
|
console.warn('stateWatch: Callback function is required');
|
|
817
808
|
return;
|
|
818
809
|
}
|
|
819
|
-
const dep = new Set()
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
810
|
+
const dep = new Set();
|
|
811
|
+
|
|
812
|
+
const runner = () => {
|
|
813
|
+
if (!watchCallbacks.has(callback)) {
|
|
814
|
+
watchCallbacks.set(callback, true);
|
|
815
|
+
Promise.resolve().then(() => {
|
|
816
|
+
if (effect.cleanup) {
|
|
817
|
+
effect.cleanup();
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
const result = runWithEffect(runner, callback);
|
|
821
|
+
if (typeof result === 'function') {
|
|
822
|
+
effect.cleanup = result;
|
|
823
|
+
}
|
|
824
|
+
watchCallbacks.delete(callback);
|
|
825
|
+
});
|
|
826
|
+
}
|
|
827
|
+
};
|
|
828
|
+
runner._id = crypto.randomUUID();
|
|
829
|
+
|
|
825
830
|
const effect = {
|
|
826
|
-
callback:
|
|
827
|
-
if (!watchCallbacks.has(callback)) {
|
|
828
|
-
watchCallbacks.set(callback, true);
|
|
829
|
-
Promise.resolve().then(() => {
|
|
830
|
-
if (effect.cleanup) {
|
|
831
|
-
effect.cleanup();
|
|
832
|
-
}
|
|
833
|
-
const result = callback();
|
|
834
|
-
// Handle cleanup function returned from callback
|
|
835
|
-
if (typeof result === 'function') {
|
|
836
|
-
effect.cleanup = result;
|
|
837
|
-
}
|
|
838
|
-
watchCallbacks.delete(callback);
|
|
839
|
-
});
|
|
840
|
-
}
|
|
841
|
-
},
|
|
831
|
+
callback: runner,
|
|
842
832
|
deps: dep,
|
|
843
833
|
cleanup: null,
|
|
844
834
|
};
|
|
845
835
|
|
|
846
|
-
// Initial run with
|
|
847
|
-
|
|
836
|
+
// Initial run with auto-tracking for explicit dependencies and the main callback
|
|
837
|
+
if (dependencies) {
|
|
838
|
+
dependencies.forEach(d => {
|
|
839
|
+
if (typeof d === 'function') {
|
|
840
|
+
runWithEffect(runner, d);
|
|
841
|
+
} else if (d && d.id) {
|
|
842
|
+
dep.add(d.id);
|
|
843
|
+
runWithEffect(runner, () => d.value);
|
|
844
|
+
}
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
const result = runWithEffect(runner, callback);
|
|
848
849
|
if (typeof result === 'function') {
|
|
849
850
|
effect.cleanup = result;
|
|
850
851
|
}
|
|
851
852
|
|
|
852
|
-
globalEffectMap.set(callback, effect);
|
|
853
|
-
|
|
854
853
|
return () => {
|
|
855
854
|
if (effect.cleanup) {
|
|
856
855
|
effect.cleanup();
|
|
857
856
|
}
|
|
858
|
-
globalEffectMap.delete(callback);
|
|
859
857
|
watchCallbacks.delete(callback);
|
|
858
|
+
deleteEffect.add(runner._id);
|
|
860
859
|
};
|
|
861
860
|
};
|
|
862
861
|
|
package/package.json
CHANGED
package/reactive.js
CHANGED
|
@@ -7,8 +7,17 @@
|
|
|
7
7
|
export const componentMount=new Map()
|
|
8
8
|
let queue = new Set();
|
|
9
9
|
let isFlushing = false;
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
export const deleteEffect = new Set();
|
|
11
|
+
|
|
12
|
+
export const runWithEffect = (effect, fn) => {
|
|
13
|
+
const prev = activeEffect;
|
|
14
|
+
activeEffect = effect;
|
|
15
|
+
try {
|
|
16
|
+
return fn();
|
|
17
|
+
} finally {
|
|
18
|
+
activeEffect = prev;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
12
21
|
|
|
13
22
|
|
|
14
23
|
const scheduled = new Set();
|