@preact/signals 2.6.0 → 2.6.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @preact/signals
2
2
 
3
+ ## 2.6.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#836](https://github.com/preactjs/signals/pull/836) [`ac5032e`](https://github.com/preactjs/signals/commit/ac5032e63000cdb0bf84e20a1b44c161788a1607) Thanks [@JoviDeCroock](https://github.com/JoviDeCroock)! - Ensure that the `For` and `Show` component have display-names
8
+
3
9
  ## 2.6.0
4
10
 
5
11
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@preact/signals",
3
- "version": "2.6.0",
3
+ "version": "2.6.1",
4
4
  "license": "MIT",
5
5
  "description": "Manage state with style in Preact",
6
6
  "keywords": [],
@@ -6,12 +6,18 @@ interface ShowProps<T = boolean> {
6
6
  children: ComponentChildren | ((value: NonNullable<T>) => ComponentChildren);
7
7
  }
8
8
  export declare function Show<T = boolean>(props: ShowProps<T>): ComponentChildren | null;
9
+ export declare namespace Show {
10
+ var displayName: string;
11
+ }
9
12
  interface ForProps<T> {
10
13
  each: Signal<Array<T>> | ReadonlySignal<Array<T>> | (() => Signal<Array<T>> | ReadonlySignal<Array<T>>);
11
14
  fallback?: ComponentChildren;
12
15
  children: (value: T, index: number) => ComponentChildren;
13
16
  }
14
17
  export declare function For<T>(props: ForProps<T>): ComponentChildren | null;
18
+ export declare namespace For {
19
+ var displayName: string;
20
+ }
15
21
  export declare function useLiveSignal<T>(value: T): Signal<T>;
16
22
  export declare function useSignalRef<T>(value: T): Signal<T> & {
17
23
  current: T;
@@ -1 +1 @@
1
- var n=require("@preact/signals"),r=require("preact"),t=require("preact/hooks"),e=function(n){return"function"==typeof n.children?n.children(n.v,n.i):n.children},u={configurable:!0,get:function(){return this.value},set:function(n){this.value=n}};exports.For=function(n){var u=t.useMemo(function(){return new Map},[]),i=("function"==typeof n.each?n.each():n.each).value;if(!i.length)return n.fallback||null;var o=new Set(u.keys()),c=i.map(function(t,i){o.delete(t);if(!u.has(t)){var c=r.createElement(e,{v:t,i:i,children:n.children});u.set(t,c);return c}return u.get(t)});o.forEach(function(n){u.delete(n)});return r.createElement(r.Fragment,null,c)};exports.Show=function(n){var t="function"==typeof n.when?n.when():n.when.value;if(!t)return n.fallback||null;else return r.createElement(e,{v:t,children:n.children})};exports.useLiveSignal=function(r){var t=n.useSignal(r);if(t.peek()!==r)t.value=r;return t};exports.useSignalRef=function(r){var t=n.useSignal(r);if(!("current"in t))Object.defineProperty(t,"current",u);return t};//# sourceMappingURL=utils.js.map
1
+ var r=require("@preact/signals"),n=require("preact"),t=require("preact/hooks"),e=function(r){return"function"==typeof r.children?r.children(r.v,r.i):r.children};e.displayName="Item";function u(r){var t="function"==typeof r.when?r.when():r.when.value;if(!t)return r.fallback||null;else return n.createElement(e,{v:t,children:r.children})}u.displayName="Show";function i(r){var u=t.useMemo(function(){return new Map},[]),i=("function"==typeof r.each?r.each():r.each).value;if(!i.length)return r.fallback||null;var o=new Set(u.keys()),c=i.map(function(t,i){o.delete(t);if(!u.has(t)){var c=n.createElement(e,{v:t,i:i,children:r.children});u.set(t,c);return c}return u.get(t)});o.forEach(function(r){u.delete(r)});return n.createElement(n.Fragment,null,c)}i.displayName="For";var o={configurable:!0,get:function(){return this.value},set:function(r){this.value=r}};exports.For=i;exports.Show=u;exports.useLiveSignal=function(n){var t=r.useSignal(n);if(t.peek()!==n)t.value=n;return t};exports.useSignalRef=function(n){var t=r.useSignal(n);if(!("current"in t))Object.defineProperty(t,"current",o);return t};//# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sources":["../src/index.tsx"],"sourcesContent":["import { ReadonlySignal, Signal } from \"@preact/signals-core\";\nimport { useSignal } from \"@preact/signals\";\nimport { Fragment, createElement, ComponentChildren } from \"preact\";\nimport { useMemo } from \"preact/hooks\";\n\ninterface ShowProps<T = boolean> {\n\twhen: Signal<T> | ReadonlySignal<T> | (() => T);\n\tfallback?: ComponentChildren;\n\tchildren: ComponentChildren | ((value: NonNullable<T>) => ComponentChildren);\n}\n\nconst Item = (props: any) => {\n\treturn typeof props.children === \"function\"\n\t\t? props.children(props.v, props.i)\n\t\t: props.children;\n};\n\nexport function Show<T = boolean>(\n\tprops: ShowProps<T>\n): ComponentChildren | null {\n\tconst value =\n\t\ttypeof props.when === \"function\" ? props.when() : props.when.value;\n\tif (!value) return props.fallback || null;\n\treturn <Item v={value} children={props.children} />;\n}\n\ninterface ForProps<T> {\n\teach:\n\t\t| Signal<Array<T>>\n\t\t| ReadonlySignal<Array<T>>\n\t\t| (() => Signal<Array<T>> | ReadonlySignal<Array<T>>);\n\tfallback?: ComponentChildren;\n\tchildren: (value: T, index: number) => ComponentChildren;\n}\n\nexport function For<T>(props: ForProps<T>): ComponentChildren | null {\n\tconst cache = useMemo(() => new Map(), []);\n\tlet list = (\n\t\t(typeof props.each === \"function\" ? props.each() : props.each) as Signal<\n\t\t\tArray<T>\n\t\t>\n\t).value;\n\n\tif (!list.length) return props.fallback || null;\n\n\tconst removed = new Set(cache.keys());\n\n\tconst items = list.map((value, key) => {\n\t\tremoved.delete(value);\n\t\tif (!cache.has(value)) {\n\t\t\tconst result = <Item v={value} i={key} children={props.children} />;\n\t\t\tcache.set(value, result);\n\t\t\treturn result;\n\t\t}\n\t\treturn cache.get(value);\n\t});\n\n\tremoved.forEach(value => {\n\t\tcache.delete(value);\n\t});\n\n\treturn createElement(Fragment, null, items);\n}\n\nexport function useLiveSignal<T>(value: T): Signal<T> {\n\tconst s = useSignal(value);\n\tif (s.peek() !== value) s.value = value;\n\treturn s;\n}\n\nexport function useSignalRef<T>(value: T): Signal<T> & { current: T } {\n\tconst ref = useSignal(value) as Signal<T> & { current: T };\n\tif (!(\"current\" in ref))\n\t\tObject.defineProperty(ref, \"current\", refSignalProto);\n\treturn ref;\n}\nconst refSignalProto = {\n\tconfigurable: true,\n\tget(this: Signal) {\n\t\treturn this.value;\n\t},\n\tset(this: Signal, v: any) {\n\t\tthis.value = v;\n\t},\n};\n"],"names":["signals","require","preact","hooks","Item","props","children","v","i","refSignalProto","configurable","get","this","value","set","exports","For","cache","useMemo","Map","list","each","length","fallback","removed","Set","keys","items","map","key","has","result","createElement","forEach","Fragment","Show","when","useLiveSignal","s","useSignal","peek","useSignalRef","ref","Object","defineProperty"],"mappings":"AAWA,IAAAA,EAAAC,QAAA,mBAAAC,EAAAD,QAAA,UAAAE,EAAAF,QAAA,gBAAMG,EAAO,SAACC,GACb,MAAiC,mBAAnBA,EAAMC,SACjBD,EAAMC,SAASD,EAAME,EAAGF,EAAMG,GAC9BH,EAAMC,QACV,EA6DMG,EAAiB,CACtBC,cAAc,EACdC,IAAA,WACC,OAAOC,KAAKC,KACb,EACAC,IAAA,SAAkBP,GACjBK,KAAKC,MAAQN,CACd,GACAQ,QAAAC,IAjDe,SAAOX,GACtB,IAAMY,EAAQC,EAAAA,QAAQ,WAAM,OAAA,IAAIC,GAAK,EAAE,IACnCC,GACoB,mBAAff,EAAMgB,KAAsBhB,EAAMgB,OAAShB,EAAMgB,MAGxDR,MAEF,IAAKO,EAAKE,OAAQ,OAAOjB,EAAMkB,UAAY,KAE3C,IAAMC,EAAU,IAAIC,IAAIR,EAAMS,QAExBC,EAAQP,EAAKQ,IAAI,SAACf,EAAOgB,GAC9BL,SAAeX,GACf,IAAKI,EAAMa,IAAIjB,GAAQ,CACtB,IAAMkB,EAASC,gBAAC5B,EAAK,CAAAG,EAAGM,EAAOL,EAAGqB,EAAKvB,SAAUD,EAAMC,WACvDW,EAAMH,IAAID,EAAOkB,GACjB,OAAOA,CACR,CACA,OAAOd,EAAMN,IAAIE,EAClB,GAEAW,EAAQS,QAAQ,SAAApB,GACfI,EAAY,OAACJ,EACd,GAEA,OAAOmB,EAAAA,cAAcE,EAAQA,SAAE,KAAMP,EACtC,EAsBCZ,QAAAoB,cAlEA9B,GAEA,IAAMQ,EACiB,mBAAfR,EAAM+B,KAAsB/B,EAAM+B,OAAS/B,EAAM+B,KAAKvB,MAC9D,IAAKA,EAAO,OAAOR,EAAMkB,UAAY,UACrC,OAAOS,EAAAA,cAAC5B,EAAK,CAAAG,EAAGM,EAAOP,SAAUD,EAAMC,UACxC,EA4DCS,QAAAsB,cApBe,SAAiBxB,GAChC,IAAMyB,EAAIC,EAAAA,UAAU1B,GACpB,GAAIyB,EAAEE,SAAW3B,EAAOyB,EAAEzB,MAAQA,EAClC,OAAOyB,CACR,EAgBCvB,QAAA0B,aAde,SAAgB5B,GAC/B,IAAM6B,EAAMH,EAAAA,UAAU1B,GACtB,KAAM,YAAa6B,GAClBC,OAAOC,eAAeF,EAAK,UAAWjC,GACvC,OAAOiC,CACR"}
1
+ {"version":3,"file":"utils.js","sources":["../src/index.tsx"],"sourcesContent":["import { ReadonlySignal, Signal } from \"@preact/signals-core\";\nimport { useSignal } from \"@preact/signals\";\nimport { Fragment, createElement, ComponentChildren } from \"preact\";\nimport { useMemo } from \"preact/hooks\";\n\ninterface ShowProps<T = boolean> {\n\twhen: Signal<T> | ReadonlySignal<T> | (() => T);\n\tfallback?: ComponentChildren;\n\tchildren: ComponentChildren | ((value: NonNullable<T>) => ComponentChildren);\n}\n\nconst Item = (props: any) => {\n\treturn typeof props.children === \"function\"\n\t\t? props.children(props.v, props.i)\n\t\t: props.children;\n};\n\nItem.displayName = \"Item\";\n\nexport function Show<T = boolean>(\n\tprops: ShowProps<T>\n): ComponentChildren | null {\n\tconst value =\n\t\ttypeof props.when === \"function\" ? props.when() : props.when.value;\n\tif (!value) return props.fallback || null;\n\treturn <Item v={value} children={props.children} />;\n}\n\nShow.displayName = \"Show\";\n\ninterface ForProps<T> {\n\teach:\n\t\t| Signal<Array<T>>\n\t\t| ReadonlySignal<Array<T>>\n\t\t| (() => Signal<Array<T>> | ReadonlySignal<Array<T>>);\n\tfallback?: ComponentChildren;\n\tchildren: (value: T, index: number) => ComponentChildren;\n}\n\nexport function For<T>(props: ForProps<T>): ComponentChildren | null {\n\tconst cache = useMemo(() => new Map(), []);\n\tlet list = (\n\t\t(typeof props.each === \"function\" ? props.each() : props.each) as Signal<\n\t\t\tArray<T>\n\t\t>\n\t).value;\n\n\tif (!list.length) return props.fallback || null;\n\n\tconst removed = new Set(cache.keys());\n\n\tconst items = list.map((value, key) => {\n\t\tremoved.delete(value);\n\t\tif (!cache.has(value)) {\n\t\t\tconst result = <Item v={value} i={key} children={props.children} />;\n\t\t\tcache.set(value, result);\n\t\t\treturn result;\n\t\t}\n\t\treturn cache.get(value);\n\t});\n\n\tremoved.forEach(value => {\n\t\tcache.delete(value);\n\t});\n\n\treturn createElement(Fragment, null, items);\n}\n\nFor.displayName = \"For\";\n\nexport function useLiveSignal<T>(value: T): Signal<T> {\n\tconst s = useSignal(value);\n\tif (s.peek() !== value) s.value = value;\n\treturn s;\n}\n\nexport function useSignalRef<T>(value: T): Signal<T> & { current: T } {\n\tconst ref = useSignal(value) as Signal<T> & { current: T };\n\tif (!(\"current\" in ref))\n\t\tObject.defineProperty(ref, \"current\", refSignalProto);\n\treturn ref;\n}\nconst refSignalProto = {\n\tconfigurable: true,\n\tget(this: Signal) {\n\t\treturn this.value;\n\t},\n\tset(this: Signal, v: any) {\n\t\tthis.value = v;\n\t},\n};\n"],"names":["Item","props","children","v","i","displayName","Show","value","when","fallback","createElement","For","cache","useMemo","Map","list","each","length","removed","Set","keys","items","map","key","has","result","set","get","forEach","Fragment","refSignalProto","configurable","this","exports","useLiveSignal","s","useSignal","peek","useSignalRef","ref","Object","defineProperty"],"mappings":"+EAWMA,EAAO,SAACC,GACb,MAAiC,mBAAnBA,EAAMC,SACjBD,EAAMC,SAASD,EAAME,EAAGF,EAAMG,GAC9BH,EAAMC,QACV,EAEAF,EAAKK,YAAc,OAEH,SAAAC,EACfL,GAEA,IAAMM,EACiB,mBAAfN,EAAMO,KAAsBP,EAAMO,OAASP,EAAMO,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!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@preact/signals"),require("preact"),require("preact/hooks")):"function"==typeof define&&define.amd?define(["exports","@preact/signals","preact","preact/hooks"],e):e((n||self).preactSignalsutils={},n.signals,n.preact,n.preactHooks)}(this,function(n,e,t,r){var i=function(n){return"function"==typeof n.children?n.children(n.v,n.i):n.children},u={configurable:!0,get:function(){return this.value},set:function(n){this.value=n}};n.For=function(n){var e=r.useMemo(function(){return new Map},[]),u=("function"==typeof n.each?n.each():n.each).value;if(!u.length)return n.fallback||null;var f=new Set(e.keys()),o=u.map(function(r,u){f.delete(r);if(!e.has(r)){var o=t.createElement(i,{v:r,i:u,children:n.children});e.set(r,o);return o}return e.get(r)});f.forEach(function(n){e.delete(n)});return t.createElement(t.Fragment,null,o)};n.Show=function(n){var e="function"==typeof n.when?n.when():n.when.value;if(!e)return n.fallback||null;else return t.createElement(i,{v:e,children:n.children})};n.useLiveSignal=function(n){var t=e.useSignal(n);if(t.peek()!==n)t.value=n;return t};n.useSignalRef=function(n){var t=e.useSignal(n);if(!("current"in t))Object.defineProperty(t,"current",u);return t}});//# sourceMappingURL=utils.min.js.map
1
+ !function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@preact/signals"),require("preact"),require("preact/hooks")):"function"==typeof define&&define.amd?define(["exports","@preact/signals","preact","preact/hooks"],e):e((n||self).preactSignalsutils={},n.signals,n.preact,n.preactHooks)}(this,function(n,e,t,r){var i=function(n){return"function"==typeof n.children?n.children(n.v,n.i):n.children};i.displayName="Item";function u(n){var e="function"==typeof n.when?n.when():n.when.value;if(!e)return n.fallback||null;else return t.createElement(i,{v:e,children:n.children})}u.displayName="Show";function o(n){var e=r.useMemo(function(){return new Map},[]),u=("function"==typeof n.each?n.each():n.each).value;if(!u.length)return n.fallback||null;var o=new Set(e.keys()),f=u.map(function(r,u){o.delete(r);if(!e.has(r)){var f=t.createElement(i,{v:r,i:u,children:n.children});e.set(r,f);return f}return e.get(r)});o.forEach(function(n){e.delete(n)});return t.createElement(t.Fragment,null,f)}o.displayName="For";var f={configurable:!0,get:function(){return this.value},set:function(n){this.value=n}};n.For=o;n.Show=u;n.useLiveSignal=function(n){var t=e.useSignal(n);if(t.peek()!==n)t.value=n;return t};n.useSignalRef=function(n){var t=e.useSignal(n);if(!("current"in t))Object.defineProperty(t,"current",f);return t}});//# sourceMappingURL=utils.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.min.js","sources":["../src/index.tsx"],"sourcesContent":["import { ReadonlySignal, Signal } from \"@preact/signals-core\";\nimport { useSignal } from \"@preact/signals\";\nimport { Fragment, createElement, ComponentChildren } from \"preact\";\nimport { useMemo } from \"preact/hooks\";\n\ninterface ShowProps<T = boolean> {\n\twhen: Signal<T> | ReadonlySignal<T> | (() => T);\n\tfallback?: ComponentChildren;\n\tchildren: ComponentChildren | ((value: NonNullable<T>) => ComponentChildren);\n}\n\nconst Item = (props: any) => {\n\treturn typeof props.children === \"function\"\n\t\t? props.children(props.v, props.i)\n\t\t: props.children;\n};\n\nexport function Show<T = boolean>(\n\tprops: ShowProps<T>\n): ComponentChildren | null {\n\tconst value =\n\t\ttypeof props.when === \"function\" ? props.when() : props.when.value;\n\tif (!value) return props.fallback || null;\n\treturn <Item v={value} children={props.children} />;\n}\n\ninterface ForProps<T> {\n\teach:\n\t\t| Signal<Array<T>>\n\t\t| ReadonlySignal<Array<T>>\n\t\t| (() => Signal<Array<T>> | ReadonlySignal<Array<T>>);\n\tfallback?: ComponentChildren;\n\tchildren: (value: T, index: number) => ComponentChildren;\n}\n\nexport function For<T>(props: ForProps<T>): ComponentChildren | null {\n\tconst cache = useMemo(() => new Map(), []);\n\tlet list = (\n\t\t(typeof props.each === \"function\" ? props.each() : props.each) as Signal<\n\t\t\tArray<T>\n\t\t>\n\t).value;\n\n\tif (!list.length) return props.fallback || null;\n\n\tconst removed = new Set(cache.keys());\n\n\tconst items = list.map((value, key) => {\n\t\tremoved.delete(value);\n\t\tif (!cache.has(value)) {\n\t\t\tconst result = <Item v={value} i={key} children={props.children} />;\n\t\t\tcache.set(value, result);\n\t\t\treturn result;\n\t\t}\n\t\treturn cache.get(value);\n\t});\n\n\tremoved.forEach(value => {\n\t\tcache.delete(value);\n\t});\n\n\treturn createElement(Fragment, null, items);\n}\n\nexport function useLiveSignal<T>(value: T): Signal<T> {\n\tconst s = useSignal(value);\n\tif (s.peek() !== value) s.value = value;\n\treturn s;\n}\n\nexport function useSignalRef<T>(value: T): Signal<T> & { current: T } {\n\tconst ref = useSignal(value) as Signal<T> & { current: T };\n\tif (!(\"current\" in ref))\n\t\tObject.defineProperty(ref, \"current\", refSignalProto);\n\treturn ref;\n}\nconst refSignalProto = {\n\tconfigurable: true,\n\tget(this: Signal) {\n\t\treturn this.value;\n\t},\n\tset(this: Signal, v: any) {\n\t\tthis.value = v;\n\t},\n};\n"],"names":["g","f","exports","module","require","define","amd","globalThis","self","preactSignalsutils","signals","preact","preactHooks","this","hooks","Item","props","children","v","i","refSignalProto","configurable","get","value","set","For","cache","useMemo","Map","list","each","length","fallback","removed","Set","keys","items","map","key","has","result","createElement","forEach","Fragment","Show","when","useLiveSignal","s","useSignal","peek","useSignalRef","ref","Object","defineProperty"],"mappings":"CAWA,SAAAA,EAAAC,GAAA,iBAAAC,SAAA,oBAAAC,OAAAF,EAAAC,QAAAE,QAAA,mBAAAA,QAAA,UAAAA,QAAA,iBAAA,mBAAAC,QAAAA,OAAAC,IAAAD,OAAA,CAAA,UAAA,kBAAA,SAAA,gBAAAJ,GAAAA,GAAAD,EAAA,oBAAAO,WAAAA,WAAAP,GAAAQ,MAAAC,mBAAA,CAAA,EAAAT,EAAAU,QAAAV,EAAAW,OAAAX,EAAAY,YAAA,CAAA,CAAAC,KAAA,SAAAX,EAAAQ,EAAAC,EAAAG,GAAA,IAAMC,EAAO,SAACC,GACb,MAAiC,mBAAnBA,EAAMC,SACjBD,EAAMC,SAASD,EAAME,EAAGF,EAAMG,GAC9BH,EAAMC,QACV,EA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C,OAAO+B,CACR,CASC"}
1
+ {"version":3,"file":"utils.min.js","sources":["../src/index.tsx"],"sourcesContent":["import { ReadonlySignal, Signal } from \"@preact/signals-core\";\nimport { useSignal } from \"@preact/signals\";\nimport { Fragment, createElement, ComponentChildren } from \"preact\";\nimport { useMemo } from \"preact/hooks\";\n\ninterface ShowProps<T = boolean> {\n\twhen: Signal<T> | ReadonlySignal<T> | (() => T);\n\tfallback?: ComponentChildren;\n\tchildren: ComponentChildren | ((value: NonNullable<T>) => ComponentChildren);\n}\n\nconst Item = (props: any) => {\n\treturn typeof props.children === \"function\"\n\t\t? props.children(props.v, props.i)\n\t\t: props.children;\n};\n\nItem.displayName = \"Item\";\n\nexport function Show<T = boolean>(\n\tprops: ShowProps<T>\n): ComponentChildren | null {\n\tconst value =\n\t\ttypeof props.when === \"function\" ? props.when() : props.when.value;\n\tif (!value) return props.fallback || null;\n\treturn <Item v={value} children={props.children} />;\n}\n\nShow.displayName = \"Show\";\n\ninterface ForProps<T> {\n\teach:\n\t\t| Signal<Array<T>>\n\t\t| ReadonlySignal<Array<T>>\n\t\t| (() => Signal<Array<T>> | ReadonlySignal<Array<T>>);\n\tfallback?: ComponentChildren;\n\tchildren: (value: T, index: number) => ComponentChildren;\n}\n\nexport function For<T>(props: ForProps<T>): ComponentChildren | null {\n\tconst cache = useMemo(() => new Map(), []);\n\tlet list = (\n\t\t(typeof props.each === \"function\" ? props.each() : props.each) as Signal<\n\t\t\tArray<T>\n\t\t>\n\t).value;\n\n\tif (!list.length) return props.fallback || null;\n\n\tconst removed = new Set(cache.keys());\n\n\tconst items = list.map((value, key) => {\n\t\tremoved.delete(value);\n\t\tif (!cache.has(value)) {\n\t\t\tconst result = <Item v={value} i={key} children={props.children} />;\n\t\t\tcache.set(value, result);\n\t\t\treturn result;\n\t\t}\n\t\treturn cache.get(value);\n\t});\n\n\tremoved.forEach(value => {\n\t\tcache.delete(value);\n\t});\n\n\treturn createElement(Fragment, null, items);\n}\n\nFor.displayName = \"For\";\n\nexport function useLiveSignal<T>(value: T): Signal<T> {\n\tconst s = useSignal(value);\n\tif (s.peek() !== value) s.value = value;\n\treturn s;\n}\n\nexport function useSignalRef<T>(value: T): Signal<T> & { current: T } {\n\tconst ref = useSignal(value) as Signal<T> & { current: T };\n\tif (!(\"current\" in ref))\n\t\tObject.defineProperty(ref, \"current\", refSignalProto);\n\treturn ref;\n}\nconst refSignalProto = {\n\tconfigurable: true,\n\tget(this: Signal) {\n\t\treturn this.value;\n\t},\n\tset(this: Signal, v: any) {\n\t\tthis.value = v;\n\t},\n};\n"],"names":["Item","props","children","v","i","displayName","Show","value","when","fallback","createElement","For","cache","useMemo","Map","list","each","length","removed","Set","keys","items","map","key","has","result","set","get","forEach","Fragment","refSignalProto","configurable","this","exports","useLiveSignal","s","useSignal","peek","useSignalRef","ref","Object","defineProperty"],"mappings":"kYAWA,IAAMA,EAAO,SAACC,GACb,MAAiC,mBAAnBA,EAAMC,SACjBD,EAAMC,SAASD,EAAME,EAAGF,EAAMG,GAC9BH,EAAMC,QACV,EAEAF,EAAKK,YAAc,OAEH,SAAAC,EACfL,GAEA,IAAMM,EACiB,mBAAfN,EAAMO,KAAsBP,EAAMO,OAASP,EAAMO,KAAKD,MAC9D,IAAKA,EAAO,OAAON,EAAMQ,UAAY,UACrC,OAAOC,gBAACV,EAAK,CAAAG,EAAGI,EAAOL,SAAUD,EAAMC,UACxC,CAEAI,EAAKD,YAAc,OAWb,SAAUM,EAAOV,GACtB,IAAMW,EAAQC,EAAAA,QAAQ,WAAA,OAAU,IAAAC,GAAK,EAAE,IACnCC,GACoB,mBAAfd,EAAMe,KAAsBf,EAAMe,OAASf,EAAMe,MAGxDT,MAEF,IAAKQ,EAAKE,OAAQ,OAAOhB,EAAMQ,UAAY,KAE3C,IAAMS,EAAU,IAAIC,IAAIP,EAAMQ,QAExBC,EAAQN,EAAKO,IAAI,SAACf,EAAOgB,GAC9BL,SAAeX,GACf,IAAKK,EAAMY,IAAIjB,GAAQ,CACtB,IAAMkB,EAASf,EAAAA,cAACV,EAAK,CAAAG,EAAGI,EAAOH,EAAGmB,EAAKrB,SAAUD,EAAMC,WACvDU,EAAMc,IAAInB,EAAOkB,GACjB,OAAOA,CACR,CACA,OAAOb,EAAMe,IAAIpB,EAClB,GAEAW,EAAQU,QAAQ,SAAArB,GACfK,EAAY,OAACL,EACd,GAEA,OAAOG,EAAaA,cAACmB,WAAU,KAAMR,EACtC,CAEAV,EAAIN,YAAc,MAclB,IAAMyB,EAAiB,CACtBC,cAAc,EACdJ,eACC,YAAYpB,KACb,EACAmB,IAAG,SAAevB,GACjB6B,KAAKzB,MAAQJ,CACd,GACA8B,EAAAtB,IAAAA,EAAAsB,EAAA3B,KAAAA,EAAA2B,EAAAC,cApBe,SAAiB3B,GAChC,IAAM4B,EAAIC,EAASA,UAAC7B,GACpB,GAAI4B,EAAEE,SAAW9B,EAAO4B,EAAE5B,MAAQA,EAClC,OAAO4B,CACR,EAgBCF,EAAAK,aAdK,SAA0B/B,GAC/B,IAAMgC,EAAMH,EAAAA,UAAU7B,GACtB,KAAM,YAAagC,GAClBC,OAAOC,eAAeF,EAAK,UAAWT,GACvC,OAAOS,CACR,CASC"}
@@ -1 +1 @@
1
- import{useSignal}from"@preact/signals";import{createElement as n,Fragment as t}from"preact";import{useMemo as r}from"preact/hooks";const e=n=>"function"==typeof n.children?n.children(n.v,n.i):n.children;function o(t){const r="function"==typeof t.when?t.when():t.when.value;if(!r)return t.fallback||null;else return n(e,{v:r,children:t.children})}function c(o){const c=r(()=>new Map,[]);let i=("function"==typeof o.each?o.each():o.each).value;if(!i.length)return o.fallback||null;const u=new Set(c.keys()),f=i.map((t,r)=>{u.delete(t);if(!c.has(t)){const i=n(e,{v:t,i:r,children:o.children});c.set(t,i);return i}return c.get(t)});u.forEach(n=>{c.delete(n)});return n(t,null,f)}function i(n){const t=useSignal(n);if(t.peek()!==n)t.value=n;return t}function u(n){const t=useSignal(n);if(!("current"in t))Object.defineProperty(t,"current",f);return t}const f={configurable:!0,get(){return this.value},set(n){this.value=n}};export{c as For,o as Show,i as useLiveSignal,u as useSignalRef};//# sourceMappingURL=utils.mjs.map
1
+ import{useSignal}from"@preact/signals";import{createElement as t,Fragment as n}from"preact";import{useMemo as r}from"preact/hooks";const e=t=>"function"==typeof t.children?t.children(t.v,t.i):t.children;e.displayName="Item";function o(n){const r="function"==typeof n.when?n.when():n.when.value;if(!r)return n.fallback||null;else return t(e,{v:r,children:n.children})}o.displayName="Show";function c(o){const c=r(()=>new Map,[]);let i=("function"==typeof o.each?o.each():o.each).value;if(!i.length)return o.fallback||null;const u=new Set(c.keys()),f=i.map((n,r)=>{u.delete(n);if(!c.has(n)){const i=t(e,{v:n,i:r,children:o.children});c.set(n,i);return i}return c.get(n)});u.forEach(t=>{c.delete(t)});return t(n,null,f)}c.displayName="For";function i(t){const n=useSignal(t);if(n.peek()!==t)n.value=t;return n}function u(t){const n=useSignal(t);if(!("current"in n))Object.defineProperty(n,"current",f);return n}const f={configurable:!0,get(){return this.value},set(t){this.value=t}};export{c as For,o as Show,i as useLiveSignal,u as useSignalRef};//# sourceMappingURL=utils.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.mjs","sources":["../src/index.tsx"],"sourcesContent":["import { ReadonlySignal, Signal } from \"@preact/signals-core\";\nimport { useSignal } from \"@preact/signals\";\nimport { Fragment, createElement, ComponentChildren } from \"preact\";\nimport { useMemo } from \"preact/hooks\";\n\ninterface ShowProps<T = boolean> {\n\twhen: Signal<T> | ReadonlySignal<T> | (() => T);\n\tfallback?: ComponentChildren;\n\tchildren: ComponentChildren | ((value: NonNullable<T>) => ComponentChildren);\n}\n\nconst Item = (props: any) => {\n\treturn typeof props.children === \"function\"\n\t\t? props.children(props.v, props.i)\n\t\t: props.children;\n};\n\nexport function Show<T = boolean>(\n\tprops: ShowProps<T>\n): ComponentChildren | null {\n\tconst value =\n\t\ttypeof props.when === \"function\" ? props.when() : props.when.value;\n\tif (!value) return props.fallback || null;\n\treturn <Item v={value} children={props.children} />;\n}\n\ninterface ForProps<T> {\n\teach:\n\t\t| Signal<Array<T>>\n\t\t| ReadonlySignal<Array<T>>\n\t\t| (() => Signal<Array<T>> | ReadonlySignal<Array<T>>);\n\tfallback?: ComponentChildren;\n\tchildren: (value: T, index: number) => ComponentChildren;\n}\n\nexport function For<T>(props: ForProps<T>): ComponentChildren | null {\n\tconst cache = useMemo(() => new Map(), []);\n\tlet list = (\n\t\t(typeof props.each === \"function\" ? props.each() : props.each) as Signal<\n\t\t\tArray<T>\n\t\t>\n\t).value;\n\n\tif (!list.length) return props.fallback || null;\n\n\tconst removed = new Set(cache.keys());\n\n\tconst items = list.map((value, key) => {\n\t\tremoved.delete(value);\n\t\tif (!cache.has(value)) {\n\t\t\tconst result = <Item v={value} i={key} children={props.children} />;\n\t\t\tcache.set(value, result);\n\t\t\treturn result;\n\t\t}\n\t\treturn cache.get(value);\n\t});\n\n\tremoved.forEach(value => {\n\t\tcache.delete(value);\n\t});\n\n\treturn createElement(Fragment, null, items);\n}\n\nexport function useLiveSignal<T>(value: T): Signal<T> {\n\tconst s = useSignal(value);\n\tif (s.peek() !== value) s.value = value;\n\treturn s;\n}\n\nexport function useSignalRef<T>(value: T): Signal<T> & { current: T } {\n\tconst ref = useSignal(value) as Signal<T> & { current: T };\n\tif (!(\"current\" in ref))\n\t\tObject.defineProperty(ref, \"current\", refSignalProto);\n\treturn ref;\n}\nconst refSignalProto = {\n\tconfigurable: true,\n\tget(this: Signal) {\n\t\treturn this.value;\n\t},\n\tset(this: Signal, v: any) {\n\t\tthis.value = v;\n\t},\n};\n"],"names":["useSignal","createElement","Fragment","useMemo","Item","props","children","v","i","Show","value","when","fallback","For","cache","Map","list","each","length","removed","Set","keys","items","map","key","delete","has","result","set","get","forEach","useLiveSignal","s","peek","useSignalRef","ref","Object","defineProperty","refSignalProto","configurable","this"],"mappings":"OAWAA,cAAA,0CAAAC,cAAAC,MAAA,2BAAAC,MAAA,eAAA,MAAMC,EAAQC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J,UAAAsB,mBAAAG"}
1
+ {"version":3,"file":"utils.mjs","sources":["../src/index.tsx"],"sourcesContent":["import { ReadonlySignal, Signal } from \"@preact/signals-core\";\nimport { useSignal } from \"@preact/signals\";\nimport { Fragment, createElement, ComponentChildren } from \"preact\";\nimport { useMemo } from \"preact/hooks\";\n\ninterface ShowProps<T = boolean> {\n\twhen: Signal<T> | ReadonlySignal<T> | (() => T);\n\tfallback?: ComponentChildren;\n\tchildren: ComponentChildren | ((value: NonNullable<T>) => ComponentChildren);\n}\n\nconst Item = (props: any) => {\n\treturn typeof props.children === \"function\"\n\t\t? props.children(props.v, props.i)\n\t\t: props.children;\n};\n\nItem.displayName = \"Item\";\n\nexport function Show<T = boolean>(\n\tprops: ShowProps<T>\n): ComponentChildren | null {\n\tconst value =\n\t\ttypeof props.when === \"function\" ? props.when() : props.when.value;\n\tif (!value) return props.fallback || null;\n\treturn <Item v={value} children={props.children} />;\n}\n\nShow.displayName = \"Show\";\n\ninterface ForProps<T> {\n\teach:\n\t\t| Signal<Array<T>>\n\t\t| ReadonlySignal<Array<T>>\n\t\t| (() => Signal<Array<T>> | ReadonlySignal<Array<T>>);\n\tfallback?: ComponentChildren;\n\tchildren: (value: T, index: number) => ComponentChildren;\n}\n\nexport function For<T>(props: ForProps<T>): ComponentChildren | null {\n\tconst cache = useMemo(() => new Map(), []);\n\tlet list = (\n\t\t(typeof props.each === \"function\" ? props.each() : props.each) as Signal<\n\t\t\tArray<T>\n\t\t>\n\t).value;\n\n\tif (!list.length) return props.fallback || null;\n\n\tconst removed = new Set(cache.keys());\n\n\tconst items = list.map((value, key) => {\n\t\tremoved.delete(value);\n\t\tif (!cache.has(value)) {\n\t\t\tconst result = <Item v={value} i={key} children={props.children} />;\n\t\t\tcache.set(value, result);\n\t\t\treturn result;\n\t\t}\n\t\treturn cache.get(value);\n\t});\n\n\tremoved.forEach(value => {\n\t\tcache.delete(value);\n\t});\n\n\treturn createElement(Fragment, null, items);\n}\n\nFor.displayName = \"For\";\n\nexport function useLiveSignal<T>(value: T): Signal<T> {\n\tconst s = useSignal(value);\n\tif (s.peek() !== value) s.value = value;\n\treturn s;\n}\n\nexport function useSignalRef<T>(value: T): Signal<T> & { current: T } {\n\tconst ref = useSignal(value) as Signal<T> & { current: T };\n\tif (!(\"current\" in ref))\n\t\tObject.defineProperty(ref, \"current\", refSignalProto);\n\treturn ref;\n}\nconst refSignalProto = {\n\tconfigurable: true,\n\tget(this: Signal) {\n\t\treturn this.value;\n\t},\n\tset(this: Signal, v: any) {\n\t\tthis.value = v;\n\t},\n};\n"],"names":["useSignal","createElement","Fragment","useMemo","Item","props","children","v","i","displayName","Show","value","when","fallback","For","cache","Map","list","each","length","removed","Set","keys","items","map","key","delete","has","result","set","get","forEach","useLiveSignal","s","peek","useSignalRef","ref","Object","defineProperty","refSignalProto","configurable","this"],"mappings":"OAWAA,cAAA,0CAAAC,cAAAC,MAAA,2BAAAC,MAAA,eAAA,MAAMC,EAAQC,GACoB,mBAAnBA,EAAMC,SACjBD,EAAMC,SAASD,EAAME,EAAGF,EAAMG,GAC9BH,EAAMC,SAGVF,EAAKK,YAAc,gBAEHC,EACfL,GAEA,MAAMM,EACiB,mBAAfN,EAAMO,KAAsBP,EAAMO,OAASP,EAAMO,KAAKD,MAC9D,IAAKA,EAAO,OAAON,EAAMQ,UAAY,UACrC,OAAOZ,EAACG,EAAK,CAAAG,EAAGI,EAAOL,SAAUD,EAAMC,UACxC,CAEAI,EAAKD,YAAc,OAWH,SAAAK,EAAOT,GACtB,MAAMU,EAAQZ,EAAQ,IAAM,IAAIa,IAAO,IACvC,IAAIC,GACoB,mBAAfZ,EAAMa,KAAsBb,EAAMa,OAASb,EAAMa,MAGxDP,MAEF,IAAKM,EAAKE,OAAQ,OAAOd,EAAMQ,UAAY,KAE3C,MAAMO,EAAU,IAAIC,IAAIN,EAAMO,QAExBC,EAAQN,EAAKO,IAAI,CAACb,EAAOc,KAC9BL,EAAQM,OAAOf,GACf,IAAKI,EAAMY,IAAIhB,GAAQ,CACtB,MAAMiB,EAAS3B,EAACG,EAAK,CAAAG,EAAGI,EAAOH,EAAGiB,EAAKnB,SAAUD,EAAMC,WACvDS,EAAMc,IAAIlB,EAAOiB,GACjB,OAAOA,CACR,CACA,OAAOb,EAAMe,IAAInB,EAAK,GAGvBS,EAAQW,QAAQpB,IACfI,EAAMW,OAAOf,EACd,GAEA,OAAOV,EAAcC,EAAU,KAAMqB,EACtC,CAEAT,EAAIL,YAAc,MAEZ,SAAUuB,EAAiBrB,GAChC,MAAMsB,EAAIjC,UAAUW,GACpB,GAAIsB,EAAEC,SAAWvB,EAAOsB,EAAEtB,MAAQA,EAClC,OAAOsB,CACR,CAEgB,SAAAE,EAAgBxB,GAC/B,MAAMyB,EAAMpC,UAAUW,GACtB,KAAM,YAAayB,GAClBC,OAAOC,eAAeF,EAAK,UAAWG,GACvC,OAAOH,CACR,CACA,MAAMG,EAAiB,CACtBC,cAAc,EACdV,MACC,OAAWW,KAAC9B,KACb,EACAkB,IAAkBtB,GACjBkC,KAAK9B,MAAQJ,CACd,UACAO,SAAAJ,UAAAsB,mBAAAG"}
@@ -1 +1 @@
1
- import{useSignal}from"@preact/signals";import{createElement as n,Fragment as r}from"preact";import{useMemo as t}from"preact/hooks";var e=function(n){return"function"==typeof n.children?n.children(n.v,n.i):n.children};function u(r){var t="function"==typeof r.when?r.when():r.when.value;if(!t)return r.fallback||null;else return n(e,{v:t,children:r.children})}function i(u){var i=t(function(){return new Map},[]),o=("function"==typeof u.each?u.each():u.each).value;if(!o.length)return u.fallback||null;var f=new Set(i.keys()),c=o.map(function(r,t){f.delete(r);if(!i.has(r)){var o=n(e,{v:r,i:t,children:u.children});i.set(r,o);return o}return i.get(r)});f.forEach(function(n){i.delete(n)});return n(r,null,c)}function o(n){var r=useSignal(n);if(r.peek()!==n)r.value=n;return r}function f(n){var r=useSignal(n);if(!("current"in r))Object.defineProperty(r,"current",c);return r}var c={configurable:!0,get:function(){return this.value},set:function(n){this.value=n}};export{i as For,u as Show,o as useLiveSignal,f as useSignalRef};//# sourceMappingURL=utils.module.js.map
1
+ import{useSignal}from"@preact/signals";import{createElement as n,Fragment as r}from"preact";import{useMemo as t}from"preact/hooks";var e=function(n){return"function"==typeof n.children?n.children(n.v,n.i):n.children};e.displayName="Item";function u(r){var t="function"==typeof r.when?r.when():r.when.value;if(!t)return r.fallback||null;else return n(e,{v:t,children:r.children})}u.displayName="Show";function i(u){var i=t(function(){return new Map},[]),o=("function"==typeof u.each?u.each():u.each).value;if(!o.length)return u.fallback||null;var f=new Set(i.keys()),c=o.map(function(r,t){f.delete(r);if(!i.has(r)){var o=n(e,{v:r,i:t,children:u.children});i.set(r,o);return o}return i.get(r)});f.forEach(function(n){i.delete(n)});return n(r,null,c)}i.displayName="For";function o(n){var r=useSignal(n);if(r.peek()!==n)r.value=n;return r}function f(n){var r=useSignal(n);if(!("current"in r))Object.defineProperty(r,"current",c);return r}var c={configurable:!0,get:function(){return this.value},set:function(n){this.value=n}};export{i as For,u as Show,o as useLiveSignal,f as useSignalRef};//# sourceMappingURL=utils.module.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.module.js","sources":["../src/index.tsx"],"sourcesContent":["import { ReadonlySignal, Signal } from \"@preact/signals-core\";\nimport { useSignal } from \"@preact/signals\";\nimport { Fragment, createElement, ComponentChildren } from \"preact\";\nimport { useMemo } from \"preact/hooks\";\n\ninterface ShowProps<T = boolean> {\n\twhen: Signal<T> | ReadonlySignal<T> | (() => T);\n\tfallback?: ComponentChildren;\n\tchildren: ComponentChildren | ((value: NonNullable<T>) => ComponentChildren);\n}\n\nconst Item = (props: any) => {\n\treturn typeof props.children === \"function\"\n\t\t? props.children(props.v, props.i)\n\t\t: props.children;\n};\n\nexport function Show<T = boolean>(\n\tprops: ShowProps<T>\n): ComponentChildren | null {\n\tconst value =\n\t\ttypeof props.when === \"function\" ? props.when() : props.when.value;\n\tif (!value) return props.fallback || null;\n\treturn <Item v={value} children={props.children} />;\n}\n\ninterface ForProps<T> {\n\teach:\n\t\t| Signal<Array<T>>\n\t\t| ReadonlySignal<Array<T>>\n\t\t| (() => Signal<Array<T>> | ReadonlySignal<Array<T>>);\n\tfallback?: ComponentChildren;\n\tchildren: (value: T, index: number) => ComponentChildren;\n}\n\nexport function For<T>(props: ForProps<T>): ComponentChildren | null {\n\tconst cache = useMemo(() => new Map(), []);\n\tlet list = (\n\t\t(typeof props.each === \"function\" ? props.each() : props.each) as Signal<\n\t\t\tArray<T>\n\t\t>\n\t).value;\n\n\tif (!list.length) return props.fallback || null;\n\n\tconst removed = new Set(cache.keys());\n\n\tconst items = list.map((value, key) => {\n\t\tremoved.delete(value);\n\t\tif (!cache.has(value)) {\n\t\t\tconst result = <Item v={value} i={key} children={props.children} />;\n\t\t\tcache.set(value, result);\n\t\t\treturn result;\n\t\t}\n\t\treturn cache.get(value);\n\t});\n\n\tremoved.forEach(value => {\n\t\tcache.delete(value);\n\t});\n\n\treturn createElement(Fragment, null, items);\n}\n\nexport function useLiveSignal<T>(value: T): Signal<T> {\n\tconst s = useSignal(value);\n\tif (s.peek() !== value) s.value = value;\n\treturn s;\n}\n\nexport function useSignalRef<T>(value: T): Signal<T> & { current: T } {\n\tconst ref = useSignal(value) as Signal<T> & { current: T };\n\tif (!(\"current\" in ref))\n\t\tObject.defineProperty(ref, \"current\", refSignalProto);\n\treturn ref;\n}\nconst refSignalProto = {\n\tconfigurable: true,\n\tget(this: Signal) {\n\t\treturn this.value;\n\t},\n\tset(this: Signal, v: any) {\n\t\tthis.value = v;\n\t},\n};\n"],"names":["useSignal","createElement","Fragment","useMemo","Item","props","children","v","i","Show","value","when","fallback","For","cache","Map","list","each","length","removed","Set","keys","items","map","key","has","result","set","get","forEach","useLiveSignal","s","peek","useSignalRef","ref","Object","defineProperty","refSignalProto","configurable","this"],"mappings":"OAWAA,cAAA,0CAAAC,cAAAC,MAAA,2BAAAC,MAAA,eAAA,IAAMC,EAAO,SAACC,GACb,MAAiC,mBAAnBA,EAAM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,UACAM,SAAAJ,UAAAqB,mBAAAG"}
1
+ {"version":3,"file":"utils.module.js","sources":["../src/index.tsx"],"sourcesContent":["import { ReadonlySignal, Signal } from \"@preact/signals-core\";\nimport { useSignal } from \"@preact/signals\";\nimport { Fragment, createElement, ComponentChildren } from \"preact\";\nimport { useMemo } from \"preact/hooks\";\n\ninterface ShowProps<T = boolean> {\n\twhen: Signal<T> | ReadonlySignal<T> | (() => T);\n\tfallback?: ComponentChildren;\n\tchildren: ComponentChildren | ((value: NonNullable<T>) => ComponentChildren);\n}\n\nconst Item = (props: any) => {\n\treturn typeof props.children === \"function\"\n\t\t? props.children(props.v, props.i)\n\t\t: props.children;\n};\n\nItem.displayName = \"Item\";\n\nexport function Show<T = boolean>(\n\tprops: ShowProps<T>\n): ComponentChildren | null {\n\tconst value =\n\t\ttypeof props.when === \"function\" ? props.when() : props.when.value;\n\tif (!value) return props.fallback || null;\n\treturn <Item v={value} children={props.children} />;\n}\n\nShow.displayName = \"Show\";\n\ninterface ForProps<T> {\n\teach:\n\t\t| Signal<Array<T>>\n\t\t| ReadonlySignal<Array<T>>\n\t\t| (() => Signal<Array<T>> | ReadonlySignal<Array<T>>);\n\tfallback?: ComponentChildren;\n\tchildren: (value: T, index: number) => ComponentChildren;\n}\n\nexport function For<T>(props: ForProps<T>): ComponentChildren | null {\n\tconst cache = useMemo(() => new Map(), []);\n\tlet list = (\n\t\t(typeof props.each === \"function\" ? props.each() : props.each) as Signal<\n\t\t\tArray<T>\n\t\t>\n\t).value;\n\n\tif (!list.length) return props.fallback || null;\n\n\tconst removed = new Set(cache.keys());\n\n\tconst items = list.map((value, key) => {\n\t\tremoved.delete(value);\n\t\tif (!cache.has(value)) {\n\t\t\tconst result = <Item v={value} i={key} children={props.children} />;\n\t\t\tcache.set(value, result);\n\t\t\treturn result;\n\t\t}\n\t\treturn cache.get(value);\n\t});\n\n\tremoved.forEach(value => {\n\t\tcache.delete(value);\n\t});\n\n\treturn createElement(Fragment, null, items);\n}\n\nFor.displayName = \"For\";\n\nexport function useLiveSignal<T>(value: T): Signal<T> {\n\tconst s = useSignal(value);\n\tif (s.peek() !== value) s.value = value;\n\treturn s;\n}\n\nexport function useSignalRef<T>(value: T): Signal<T> & { current: T } {\n\tconst ref = useSignal(value) as Signal<T> & { current: T };\n\tif (!(\"current\" in ref))\n\t\tObject.defineProperty(ref, \"current\", refSignalProto);\n\treturn ref;\n}\nconst refSignalProto = {\n\tconfigurable: true,\n\tget(this: Signal) {\n\t\treturn this.value;\n\t},\n\tset(this: Signal, v: any) {\n\t\tthis.value = v;\n\t},\n};\n"],"names":["Item","props","children","v","i","displayName","Show","value","when","fallback","createElement","For","cache","useMemo","Map","list","each","length","removed","Set","keys","items","map","key","has","result","set","get","forEach","Fragment","useLiveSignal","s","useSignal","peek","useSignalRef","ref","Object","defineProperty","refSignalProto","configurable","this"],"mappings":"mIAWA,IAAMA,EAAO,SAACC,GACb,MAAiC,mBAAnBA,EAAMC,SACjBD,EAAMC,SAASD,EAAME,EAAGF,EAAMG,GAC9BH,EAAMC,QACV,EAEAF,EAAKK,YAAc,OAEH,SAAAC,EACfL,GAEA,IAAMM,EACiB,mBAAfN,EAAMO,KAAsBP,EAAMO,OAASP,EAAMO,KAAKD,MAC9D,IAAKA,EAAO,OAAON,EAAMQ,UAAY,UACrC,OAAOC,EAACV,EAAK,CAAAG,EAAGI,EAAOL,SAAUD,EAAMC,UACxC,CAEAI,EAAKD,YAAc,OAWb,SAAUM,EAAOV,GACtB,IAAMW,EAAQC,EAAQ,WAAA,OAAU,IAAAC,GAAK,EAAE,IACnCC,GACoB,mBAAfd,EAAMe,KAAsBf,EAAMe,OAASf,EAAMe,MAGxDT,MAEF,IAAKQ,EAAKE,OAAQ,OAAOhB,EAAMQ,UAAY,KAE3C,IAAMS,EAAU,IAAIC,IAAIP,EAAMQ,QAExBC,EAAQN,EAAKO,IAAI,SAACf,EAAOgB,GAC9BL,SAAeX,GACf,IAAKK,EAAMY,IAAIjB,GAAQ,CACtB,IAAMkB,EAASf,EAACV,EAAK,CAAAG,EAAGI,EAAOH,EAAGmB,EAAKrB,SAAUD,EAAMC,WACvDU,EAAMc,IAAInB,EAAOkB,GACjB,OAAOA,CACR,CACA,OAAOb,EAAMe,IAAIpB,EAClB,GAEAW,EAAQU,QAAQ,SAAArB,GACfK,EAAY,OAACL,EACd,GAEA,OAAOG,EAAcmB,EAAU,KAAMR,EACtC,CAEAV,EAAIN,YAAc,MAEF,SAAAyB,EAAiBvB,GAChC,IAAMwB,EAAIC,UAAUzB,GACpB,GAAIwB,EAAEE,SAAW1B,EAAOwB,EAAExB,MAAQA,EAClC,OAAOwB,CACR,CAEM,SAAUG,EAAgB3B,GAC/B,IAAM4B,EAAMH,UAAUzB,GACtB,KAAM,YAAa4B,GAClBC,OAAOC,eAAeF,EAAK,UAAWG,GACvC,OAAOH,CACR,CACA,IAAMG,EAAiB,CACtBC,cAAc,EACdZ,eACC,YAAYpB,KACb,EACAmB,IAAG,SAAevB,GACjBqC,KAAKjC,MAAQJ,CACd,UACAQ,SAAAL,UAAAwB,mBAAAI"}
@@ -15,6 +15,8 @@ const Item = (props: any) => {
15
15
  : props.children;
16
16
  };
17
17
 
18
+ Item.displayName = "Item";
19
+
18
20
  export function Show<T = boolean>(
19
21
  props: ShowProps<T>
20
22
  ): ComponentChildren | null {
@@ -24,6 +26,8 @@ export function Show<T = boolean>(
24
26
  return <Item v={value} children={props.children} />;
25
27
  }
26
28
 
29
+ Show.displayName = "Show";
30
+
27
31
  interface ForProps<T> {
28
32
  each:
29
33
  | Signal<Array<T>>
@@ -62,6 +66,8 @@ export function For<T>(props: ForProps<T>): ComponentChildren | null {
62
66
  return createElement(Fragment, null, items);
63
67
  }
64
68
 
69
+ For.displayName = "For";
70
+
65
71
  export function useLiveSignal<T>(value: T): Signal<T> {
66
72
  const s = useSignal(value);
67
73
  if (s.peek() !== value) s.value = value;