@potch/munifw 1.0.0 → 2.0.0
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 +1 -1
- package/dist/munifw.min.js +1 -1
- package/dist/munifw.min.js.gz +0 -0
- package/dist/ssr.min.js.gz +0 -0
- package/package.json +2 -2
- package/sizes.md +1 -1
- package/src/munifw.js +2 -2
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ Create an event bus. The bus consists of two methods, an `emit` and an `on` meth
|
|
|
26
26
|
```js
|
|
27
27
|
function clock() {
|
|
28
28
|
const start = Date.now();
|
|
29
|
-
const [
|
|
29
|
+
const [emitUpdate, onUpdate] = event();
|
|
30
30
|
setInterval(() => {
|
|
31
31
|
emitUpdate(start - Date.now());
|
|
32
32
|
}, 1000);
|
package/dist/munifw.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const t="value",e=t=>"object"==typeof t,n=(t,e)=>[...t].map(e);export const using=(t,e)=>(e(),t());export const collect=(t,e,n=[])=>(using(t(t=>n.push(t)),e),n);export const event=(t=new Set)=>[(...e)=>n(t,t=>t(...e)),e=>(t.add(e),()=>t.delete(e))];const o=[];export const signal=(e,n=(t,e)=>t===e)=>{const[c,s]=event();return{set[t](t){n(e,t)||(e=t,c())},touch(){c()},get[t](){return o
|
|
1
|
+
const t="value",e=t=>"object"==typeof t,n=(t,e)=>[...t].map(e);export const using=(t,e)=>(e(),t());export const collect=(t,e,n=[])=>(using(t(t=>n.push(t)),e),n);export const event=(t=new Set)=>[(...e)=>n(t,t=>t(...e)),e=>(t.add(e),()=>t.delete(e))];const o=[];export const signal=(e,n=(t,e)=>t===e)=>{const[c,s]=event();return{set[t](t){n(e,t)||(e=t,c())},touch(){c()},get[t](){return o.at(-1)&&o.at(-1).add(this),e},peek:()=>e,watch:s}};export const[emitEffect,onEffect]=event();export const effect=(t,...e)=>{let c=0;o.push(new Set(e));const s=()=>{c||(c=1,t((...t)=>emitEffect(effect(...t))),c=0)};s();const r=n(o.at(-1),t=>t.watch(s));return o.pop(),()=>n(r,t=>t())};export const computed=(e,...n)=>{const o=signal();return o.teardown=effect(()=>o[t]=e(o[t]),...n),o};export const setProp=(n,o,c)=>{"ref"==o&&t in c?c[t]=n:e(c)&&t in c?emitEffect(effect(()=>setProp(n,o,c[t]))):"function"==typeof c||e(c)||o in n?n[o]&&e(n[o])?assign(n[o],c):n[o]=null===c?"":c:null!==c&&(0!=c||o.startsWith("data-")||o.startsWith("aria-"))?n.setAttribute(o,c):n.removeAttribute(o)};export const assign=(t,n)=>(n&&Object.entries(n).forEach(([n,o])=>{t.nodeType?setProp(t,n,o):e(t[n])&&e(o)?assign(t[n],o):t[n]=o}),t);export const dom=(t,n,...o)=>{let c;return"function"==typeof t?c=mount(()=>t(n,o)):(c=document.createElement(t),n&&e(n)&&!n.nodeType?assign(c,n):n&&o.unshift(n),c.append(...o.flat(1))),c};export const mount=(t,...e)=>{const n=[];let o;return emitEffect(effect(()=>{for(;n.length;)try{n.pop()()}catch(t){}collect(onEffect,()=>{const e=t();o&&e&&o.replaceWith(e),o=e},n)},...e)),o};export const on=(t,...e)=>(t.addEventListener(...e),()=>t.removeEventListener(...e));
|
package/dist/munifw.min.js.gz
CHANGED
|
Binary file
|
package/dist/ssr.min.js.gz
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@potch/munifw",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "A signal-driven framework for small applications",
|
|
5
5
|
"main": "src/munifw.js",
|
|
6
6
|
"scripts": {
|
|
@@ -14,6 +14,6 @@
|
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"onchange": "^7.1.0",
|
|
16
16
|
"terser": "^5.29.1",
|
|
17
|
-
"vitest": "^2.1.
|
|
17
|
+
"vitest": "^2.1.9"
|
|
18
18
|
}
|
|
19
19
|
}
|
package/sizes.md
CHANGED
package/src/munifw.js
CHANGED
|
@@ -44,8 +44,8 @@ export const signal = (value, eq = (a, b) => a === b) => {
|
|
|
44
44
|
},
|
|
45
45
|
get [val]() {
|
|
46
46
|
// if we're in an effect callback, register as a dep
|
|
47
|
-
if (context
|
|
48
|
-
context
|
|
47
|
+
if (context.at(-1)) {
|
|
48
|
+
context.at(-1).add(this);
|
|
49
49
|
}
|
|
50
50
|
return value;
|
|
51
51
|
},
|