From 4ecfad5beddfa1a4a7eea0193b3a8a1c47b4d341 Mon Sep 17 00:00:00 2001 From: Joe Pea Date: Wed, 16 Oct 2024 12:28:23 -0700 Subject: [PATCH] fix: ensure that signalifying properties already signalified by the @signal decorator does not create double signals --- dist/decorators/signal.d.ts.map | 2 +- dist/decorators/signal.js | 15 +++++---- dist/decorators/signal.js.map | 2 +- dist/decorators/signal.test.js | 52 ++++++++++++++++++++++++++++++ dist/decorators/signal.test.js.map | 2 +- dist/signals/signalify.d.ts | 1 + dist/signals/signalify.d.ts.map | 2 +- dist/signals/signalify.js | 2 +- dist/signals/signalify.js.map | 2 +- dist/signals/signalify.test.js | 2 +- dist/signals/signalify.test.js.map | 2 +- src/decorators/signal.test.ts | 43 ++++++++++++++++++++++++ src/decorators/signal.ts | 19 +++++++---- src/signals/signalify.test.ts | 2 +- src/signals/signalify.ts | 2 +- 15 files changed, 126 insertions(+), 24 deletions(-) diff --git a/dist/decorators/signal.d.ts.map b/dist/decorators/signal.d.ts.map index 1447dd4..164af78 100644 --- a/dist/decorators/signal.d.ts.map +++ b/dist/decorators/signal.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"signal.d.ts","sourceRoot":"","sources":["../../src/decorators/signal.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,OAAO,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAA;AAGjD,eAAO,IAAI,kBAAkB,wBAA+B,CAAA;AAE5D,wBAAgB,uBAAuB,SAEtC;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,MAAM,CACrB,KAAK,EAAE,OAAO,EACd,OAAO,EACJ,0BAA0B,GAC1B,2BAA2B,GAC3B,2BAA2B,GAC3B,6BAA6B,GAC9B,GAAG,CAqGL"} \ No newline at end of file +{"version":3,"file":"signal.d.ts","sourceRoot":"","sources":["../../src/decorators/signal.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,OAAO,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAA;AAGjD,eAAO,IAAI,kBAAkB,wBAA+B,CAAA;AAE5D,wBAAgB,uBAAuB,SAEtC;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,MAAM,CACrB,KAAK,EAAE,OAAO,EACd,OAAO,EACJ,0BAA0B,GAC1B,2BAA2B,GAC3B,2BAA2B,GAC3B,6BAA6B,GAC9B,GAAG,CA0GL"} \ No newline at end of file diff --git a/dist/decorators/signal.js b/dist/decorators/signal.js index 8263e38..d7f6ba4 100644 --- a/dist/decorators/signal.js +++ b/dist/decorators/signal.js @@ -1,5 +1,5 @@ import { $PROXY } from 'solid-js'; -import { __getSignal, __trackPropSetAtLeastOnce, __createSignalAccessor } from '../signals/signalify.js'; +import { __getSignal, __trackPropSetAtLeastOnce, __createSignalAccessor, isSignalGetter } from '../signals/signalify.js'; export let __propsToSignalify = new Map(); export function __resetPropsToSignalify() { __propsToSignalify = new Map(); @@ -64,11 +64,8 @@ export function signal(value, context) { let initialValue = propSpec.initialValue; // @prod-prune - if (!Object.hasOwn(this, prop)) - // continue - throw new PropNotFoundError(prop); + if (!Object.hasOwn(this, prop)) throw new PropNotFoundError(prop); __createSignalAccessor(this, prop, initialValue); - // CONTINUE testing this way of finalizing signal fields } return; } @@ -82,7 +79,7 @@ export function signal(value, context) { } = value; const signalStorage = new WeakMap(); let initialValue = undefined; - return { + const newValue = { init: function (initialVal) { initialValue = initialVal; return initialVal; @@ -99,6 +96,8 @@ export function signal(value, context) { s(typeof newValue === 'function' ? () => newValue : newValue); } }; + isSignalGetter.add(newValue.get); + return newValue; } else if (kind === 'getter' || kind === 'setter') { const getOrSet = value; const initialValue = Undefined; @@ -116,10 +115,12 @@ export function signal(value, context) { if (kind === 'getter') { pairs[name] ??= 0; pairs[name]++; - return function () { + const newGetter = function () { __getSignal(this, signalStorage, initialValue)(); return getOrSet.call(this); }; + isSignalGetter.add(newGetter); + return newGetter; } else { pairs[name] ??= 0; pairs[name]++; diff --git a/dist/decorators/signal.js.map b/dist/decorators/signal.js.map index 47bc7e0..d539ab2 100644 --- a/dist/decorators/signal.js.map +++ b/dist/decorators/signal.js.map @@ -1 +1 @@ -{"version":3,"file":"signal.js","names":["$PROXY","__getSignal","__trackPropSetAtLeastOnce","__createSignalAccessor","__propsToSignalify","Map","__resetPropsToSignalify","Undefined","Symbol","signal","value","context","kind","name","metadata","props","static","Error","queueReactiveDecoratorChecker","private","set","initialValue","undefined","proxy","prop","propSpec","Object","hasOwn","PropNotFoundError","get","signalStorage","WeakMap","init","initialVal","call","newValue","s","getOrSet","signalStoragesPerProp","signalsStorages","getterSetterPairs","pairs","queueMicrotask","MissingDecoratorError","InvalidDecorationError","checkerQueued","Array","from","keys","join","constructor","String"],"sources":["../../src/decorators/signal.ts"],"sourcesContent":["import {$PROXY} from 'solid-js'\nimport {__getSignal, __trackPropSetAtLeastOnce, __createSignalAccessor} from '../signals/signalify.js'\nimport type {PropKey, PropSpec} from './types.js'\nimport type {SignalFunction} from '../signals/createSignalFunction.js'\n\nexport let __propsToSignalify = new Map()\n\nexport function __resetPropsToSignalify() {\n\t__propsToSignalify = new Map()\n}\n\nconst Undefined = Symbol()\n\ntype SignalStorages = Record> | undefined>\n\n/**\n * @decorator\n * Decorate properties of a class with `@signal` to back them with Solid\n * signals, making them reactive. Don't forget that the class in which `@signal`\n * is used must be decorated with `@reactive`.\n *\n * Related: See the Solid.js `createSignal` API for creating signals.\n *\n * Example:\n *\n * ```js\n * import {reactive, signal} from 'classy-solid'\n * import {createEffect} from 'solid-js'\n *\n * ⁣@reactive\n * class Counter {\n * ⁣@signal count = 0\n *\n * constructor() {\n * setInterval(() => this.count++, 1000)\n * }\n * }\n *\n * const counter = new Counter\n *\n * createEffect(() => {\n * console.log('count:', counter.count)\n * })\n * ```\n */\nexport function signal(\n\tvalue: unknown,\n\tcontext:\n\t\t| ClassFieldDecoratorContext\n\t\t| ClassGetterDecoratorContext\n\t\t| ClassSetterDecoratorContext\n\t\t| ClassAccessorDecoratorContext,\n): any {\n\tconst {kind, name, metadata} = context\n\tconst props = __propsToSignalify\n\n\tif (context.static) throw new Error('@signal is not supported on static fields yet.')\n\n\t// @prod-prune\n\tqueueReactiveDecoratorChecker(props)\n\n\tif (kind === 'field') {\n\t\tif (context.private && name !== '#finalize') throw new Error('@signal is not supported on private fields yet.')\n\n\t\tif (name === '#finalize') __propsToSignalify = new Map() // reset\n\t\telse props.set(name, {initialValue: undefined, kind})\n\n\t\treturn function (this: object, initialValue: unknown) {\n\t\t\tif (name === '#finalize') {\n\t\t\t\t// Special case for Solid proxies: if the object is already a solid proxy,\n\t\t\t\t// all properties are already reactive, no need to signalify.\n\t\t\t\t// @ts-expect-error special indexed access\n\t\t\t\tconst proxy = this[$PROXY] as T\n\t\t\t\tif (proxy) return this\n\n\t\t\t\tfor (const [prop, propSpec] of props) {\n\t\t\t\t\tlet initialValue = propSpec.initialValue\n\n\t\t\t\t\t// @prod-prune\n\t\t\t\t\tif (!Object.hasOwn(this, prop))\n\t\t\t\t\t\t// continue\n\t\t\t\t\t\tthrow new PropNotFoundError(prop)\n\n\t\t\t\t\t__createSignalAccessor(this as any, prop, initialValue)\n\t\t\t\t\t// CONTINUE testing this way of finalizing signal fields\n\t\t\t\t}\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tprops.get(name)!.initialValue = initialValue\n\t\t\treturn initialValue\n\t\t}\n\t} else if (kind === 'accessor') {\n\t\tconst {get, set} = value as {get: () => unknown; set: (v: unknown) => void}\n\t\tconst signalStorage = new WeakMap>()\n\t\tlet initialValue: unknown = undefined\n\n\t\treturn {\n\t\t\tinit: function (this: object, initialVal: unknown) {\n\t\t\t\tinitialValue = initialVal\n\t\t\t\treturn initialVal\n\t\t\t},\n\t\t\tget: function (this: object): unknown {\n\t\t\t\t__getSignal(this, signalStorage, initialValue)()\n\t\t\t\treturn get.call(this)\n\t\t\t},\n\t\t\tset: function (this: object, newValue: unknown) {\n\t\t\t\tset.call(this, newValue)\n\t\t\t\t__trackPropSetAtLeastOnce(this, name) // not needed anymore? test it\n\n\t\t\t\tconst s = __getSignal(this, signalStorage, initialValue)\n\t\t\t\ts(typeof newValue === 'function' ? () => newValue : newValue)\n\t\t\t},\n\t\t}\n\t} else if (kind === 'getter' || kind === 'setter') {\n\t\tconst getOrSet = value as Function\n\t\tconst initialValue = Undefined\n\n\t\tif (!Object.hasOwn(metadata, 'signalStoragesPerProp')) metadata.signalStoragesPerProp = {}\n\t\tconst signalsStorages = metadata.signalStoragesPerProp as SignalStorages\n\n\t\tlet signalStorage = signalsStorages[name]\n\t\tif (!signalStorage) signalsStorages[name] = signalStorage = new WeakMap>()\n\n\t\tif (!Object.hasOwn(metadata, 'getterSetterPairs')) metadata.getterSetterPairs = {}\n\t\tconst pairs = metadata.getterSetterPairs as {[key: PropKey]: 0 | 1 | 2}\n\n\t\t// Show a helpful error in case someone forgets to decorate both a getter and setter.\n\t\tqueueMicrotask(() => {\n\t\t\tif (pairs[name] !== 2) throw new MissingDecoratorError(name)\n\t\t})\n\n\t\tif (kind === 'getter') {\n\t\t\tpairs[name] ??= 0\n\t\t\tpairs[name]++\n\n\t\t\treturn function (this: object): unknown {\n\t\t\t\t__getSignal(this, signalStorage, initialValue)()\n\t\t\t\treturn getOrSet.call(this)\n\t\t\t}\n\t\t} else {\n\t\t\tpairs[name] ??= 0\n\t\t\tpairs[name]++\n\n\t\t\treturn function (this: object, newValue: unknown) {\n\t\t\t\tgetOrSet.call(this, newValue)\n\t\t\t\t__trackPropSetAtLeastOnce(this, name)\n\n\t\t\t\tconst s = __getSignal(this, signalStorage, initialValue)\n\t\t\t\ts(typeof newValue === 'function' ? () => newValue : newValue)\n\t\t\t}\n\t\t}\n\t} else throw new InvalidDecorationError()\n}\n\nlet checkerQueued = false\n\n/**\n * This throws an error in some cases of an end dev forgetting to decorate a\n * class with `@reactive` if they used `@signal` on that class's fields.\n *\n * This doesn't work all the time, only when the very last class decorated is\n * missing @reactive, but something is better than nothing. There's another\n * similar check performed in the `@reactive` decorator.\n */\nfunction queueReactiveDecoratorChecker(props: Map) {\n\tif (checkerQueued) return\n\tcheckerQueued = true\n\n\tqueueMicrotask(() => {\n\t\tcheckerQueued = false\n\n\t\t// If the refs are still equal, it means @reactive did not run (forgot\n\t\t// to decorate a class that uses @signal with @reactive).\n\t\tif (props === __propsToSignalify) {\n\t\t\tthrow new Error(\n\t\t\t\t// Array.from(map.keys()) instead of [...map.keys()] because it breaks in Oculus browser.\n\t\t\t\t`Stray @signal-decorated properties detected: ${Array.from(props.keys()).join(\n\t\t\t\t\t', ',\n\t\t\t\t)}. Did you forget to use the \\`@reactive\\` decorator on a class that has properties decorated with \\`@signal\\`?`,\n\t\t\t)\n\t\t}\n\t})\n}\n\nclass PropNotFoundError extends Error {\n\tconstructor(prop: PropertyKey) {\n\t\tsuper(\n\t\t\t`Property \"${String(\n\t\t\t\tprop,\n\t\t\t)}\" not found on instance of class decorated with \\`@reactive\\`. Did you forget to use the \\`@reactive\\` decorator on one of your classes that has a \"${String(\n\t\t\t\tprop,\n\t\t\t)}\" property decorated with \\`@signal\\`?`,\n\t\t)\n\t}\n}\n\nclass MissingDecoratorError extends Error {\n\tconstructor(prop: PropertyKey) {\n\t\tsuper(\n\t\t\t`Missing @signal decorator on setter or getter for property \"${String(\n\t\t\t\tprop,\n\t\t\t)}\". The @signal decorator will only work on a getter/setter pair with *both* getter and setter decorated with @signal.`,\n\t\t)\n\t}\n}\n\nclass InvalidDecorationError extends Error {\n\tconstructor() {\n\t\tsuper('The @signal decorator is only for use on fields, getters, setters, and auto accessors.')\n\t}\n}\n"],"mappings":"AAAA,SAAQA,MAAM,QAAO,UAAU;AAC/B,SAAQC,WAAW,EAAEC,yBAAyB,EAAEC,sBAAsB,QAAO,yBAAyB;AAItG,OAAO,IAAIC,kBAAkB,GAAG,IAAIC,GAAG,CAAoB,CAAC;AAE5D,OAAO,SAASC,uBAAuBA,CAAA,EAAG;EACzCF,kBAAkB,GAAG,IAAIC,GAAG,C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AK,UAAU,GAAG,MAAMA,QAAQ,GAAGA,QAAQ,CAAC;MAC9D,CAAC;IACF;EACD,CAAC,MAAM,MAAM,IAAIS,sBAAsB,CAAC,CAAC;AAC1C;AAEA,IAAIC,aAAa,GAAG,KAAK;;AAEzB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS3B,6BAA6BA,CAACH,KAA6B,EAAE;EACrE,IAAI8B,aAAa,EAAE;EACnBA,aAAa,GAAG,IAAI;EAEpBH,cAAc,CAAC,MAAM;IACpBG,aAAa,GAAG,KAAK;;IAErB;IACA;IACA,IAAI9B,KAAK,KAAKX,kBAAkB,EAAE;MACjC,MAAM,IAAIa,KAAK;MACd;MACA,gDAAgD6B,KAAK,CAACC,IAAI,CAAChC,KAAK,CAACiC,IAAI,CAAC,CAAC,CAAC,CAACC,IAAI,CAC5E,IACD,CAAC,gHACF,CAAC;IACF;EACD,CAAC,CAAC;AACH;AAEA,MAAMrB,iBAAiB,SAASX,KAAK,CAAC;EACrCiC,WAAWA,CAAC1B,IAAiB,EAAE;IAC9B,KAAK,CACJ,aAAa2B,MAAM,CAClB3B,IACD,CAAC,uJAAuJ2B,MAAM,CAC7J3B,IACD,CAAC,wCACF,CAAC;EACF;AACD;AAEA,MAAMmB,qBAAqB,SAAS1B,KAAK,CAAC;EACzCiC,WAAWA,CAAC1B,IAAiB,EAAE;IAC9B,KAAK,CACJ,+DAA+D2B,MAAM,CACpE3B,IACD,CAAC,uHACF,CAAC;EACF;AACD;AAEA,MAAMoB,sBAAsB,SAAS3B,KAAK,CAAC;EAC1CiC,WAAWA,CAAA,EAAG;IACb,KAAK,CAAC,wFAAwF,CAAC;EAChG;AACD","ignoreList":[]} \ No newline at end of file +{"version":3,"file":"signal.js","names":["$PROXY","__getSignal","__trackPropSetAtLeastOnce","__createSignalAccessor","isSignalGetter","__propsToSignalify","Map","__resetPropsToSignalify","Undefined","Symbol","signal","value","context","kind","name","metadata","props","static","Error","queueReactiveDecoratorChecker","private","set","initialValue","undefined","proxy","prop","propSpec","Object","hasOwn","PropNotFoundError","get","signalStorage","WeakMap","newValue","init","initialVal","call","s","add","getOrSet","signalStoragesPerProp","signalsStorages","getterSetterPairs","pairs","queueMicrotask","MissingDecoratorError","newGetter","InvalidDecorationError","checkerQueued","Array","from","keys","join","constructor","String"],"sources":["../../src/decorators/signal.ts"],"sourcesContent":["import {$PROXY} from 'solid-js'\nimport {__getSignal, __trackPropSetAtLeastOnce, __createSignalAccessor, isSignalGetter} from '../signals/signalify.js'\nimport type {PropKey, PropSpec} from './types.js'\nimport type {SignalFunction} from '../signals/createSignalFunction.js'\n\nexport let __propsToSignalify = new Map()\n\nexport function __resetPropsToSignalify() {\n\t__propsToSignalify = new Map()\n}\n\nconst Undefined = Symbol()\n\ntype SignalStorages = Record> | undefined>\n\n/**\n * @decorator\n * Decorate properties of a class with `@signal` to back them with Solid\n * signals, making them reactive. Don't forget that the class in which `@signal`\n * is used must be decorated with `@reactive`.\n *\n * Related: See the Solid.js `createSignal` API for creating signals.\n *\n * Example:\n *\n * ```js\n * import {reactive, signal} from 'classy-solid'\n * import {createEffect} from 'solid-js'\n *\n * ⁣@reactive\n * class Counter {\n * ⁣@signal count = 0\n *\n * constructor() {\n * setInterval(() => this.count++, 1000)\n * }\n * }\n *\n * const counter = new Counter\n *\n * createEffect(() => {\n * console.log('count:', counter.count)\n * })\n * ```\n */\nexport function signal(\n\tvalue: unknown,\n\tcontext:\n\t\t| ClassFieldDecoratorContext\n\t\t| ClassGetterDecoratorContext\n\t\t| ClassSetterDecoratorContext\n\t\t| ClassAccessorDecoratorContext,\n): any {\n\tconst {kind, name, metadata} = context\n\tconst props = __propsToSignalify\n\n\tif (context.static) throw new Error('@signal is not supported on static fields yet.')\n\n\t// @prod-prune\n\tqueueReactiveDecoratorChecker(props)\n\n\tif (kind === 'field') {\n\t\tif (context.private && name !== '#finalize') throw new Error('@signal is not supported on private fields yet.')\n\n\t\tif (name === '#finalize') __propsToSignalify = new Map() // reset\n\t\telse props.set(name, {initialValue: undefined, kind})\n\n\t\treturn function (this: object, initialValue: unknown) {\n\t\t\tif (name === '#finalize') {\n\t\t\t\t// Special case for Solid proxies: if the object is already a solid proxy,\n\t\t\t\t// all properties are already reactive, no need to signalify.\n\t\t\t\t// @ts-expect-error special indexed access\n\t\t\t\tconst proxy = this[$PROXY] as T\n\t\t\t\tif (proxy) return this\n\n\t\t\t\tfor (const [prop, propSpec] of props) {\n\t\t\t\t\tlet initialValue = propSpec.initialValue\n\n\t\t\t\t\t// @prod-prune\n\t\t\t\t\tif (!Object.hasOwn(this, prop)) throw new PropNotFoundError(prop)\n\n\t\t\t\t\t__createSignalAccessor(this as any, prop, initialValue)\n\t\t\t\t}\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tprops.get(name)!.initialValue = initialValue\n\t\t\treturn initialValue\n\t\t}\n\t} else if (kind === 'accessor') {\n\t\tconst {get, set} = value as {get: () => unknown; set: (v: unknown) => void}\n\t\tconst signalStorage = new WeakMap>()\n\t\tlet initialValue: unknown = undefined\n\n\t\tconst newValue = {\n\t\t\tinit: function (this: object, initialVal: unknown) {\n\t\t\t\tinitialValue = initialVal\n\t\t\t\treturn initialVal\n\t\t\t},\n\t\t\tget: function (this: object): unknown {\n\t\t\t\t__getSignal(this, signalStorage, initialValue)()\n\t\t\t\treturn get.call(this)\n\t\t\t},\n\t\t\tset: function (this: object, newValue: unknown) {\n\t\t\t\tset.call(this, newValue)\n\t\t\t\t__trackPropSetAtLeastOnce(this, name) // not needed anymore? test it\n\n\t\t\t\tconst s = __getSignal(this, signalStorage, initialValue)\n\t\t\t\ts(typeof newValue === 'function' ? () => newValue : newValue)\n\t\t\t},\n\t\t}\n\n\t\tisSignalGetter.add(newValue.get)\n\n\t\treturn newValue\n\t} else if (kind === 'getter' || kind === 'setter') {\n\t\tconst getOrSet = value as Function\n\t\tconst initialValue = Undefined\n\n\t\tif (!Object.hasOwn(metadata, 'signalStoragesPerProp')) metadata.signalStoragesPerProp = {}\n\t\tconst signalsStorages = metadata.signalStoragesPerProp as SignalStorages\n\n\t\tlet signalStorage = signalsStorages[name]\n\t\tif (!signalStorage) signalsStorages[name] = signalStorage = new WeakMap>()\n\n\t\tif (!Object.hasOwn(metadata, 'getterSetterPairs')) metadata.getterSetterPairs = {}\n\t\tconst pairs = metadata.getterSetterPairs as {[key: PropKey]: 0 | 1 | 2}\n\n\t\t// Show a helpful error in case someone forgets to decorate both a getter and setter.\n\t\tqueueMicrotask(() => {\n\t\t\tif (pairs[name] !== 2) throw new MissingDecoratorError(name)\n\t\t})\n\n\t\tif (kind === 'getter') {\n\t\t\tpairs[name] ??= 0\n\t\t\tpairs[name]++\n\n\t\t\tconst newGetter = function (this: object): unknown {\n\t\t\t\t__getSignal(this, signalStorage, initialValue)()\n\t\t\t\treturn getOrSet.call(this)\n\t\t\t}\n\n\t\t\tisSignalGetter.add(newGetter)\n\n\t\t\treturn newGetter\n\t\t} else {\n\t\t\tpairs[name] ??= 0\n\t\t\tpairs[name]++\n\n\t\t\treturn function (this: object, newValue: unknown) {\n\t\t\t\tgetOrSet.call(this, newValue)\n\t\t\t\t__trackPropSetAtLeastOnce(this, name)\n\n\t\t\t\tconst s = __getSignal(this, signalStorage, initialValue)\n\t\t\t\ts(typeof newValue === 'function' ? () => newValue : newValue)\n\t\t\t}\n\t\t}\n\t} else throw new InvalidDecorationError()\n}\n\nlet checkerQueued = false\n\n/**\n * This throws an error in some cases of an end dev forgetting to decorate a\n * class with `@reactive` if they used `@signal` on that class's fields.\n *\n * This doesn't work all the time, only when the very last class decorated is\n * missing @reactive, but something is better than nothing. There's another\n * similar check performed in the `@reactive` decorator.\n */\nfunction queueReactiveDecoratorChecker(props: Map) {\n\tif (checkerQueued) return\n\tcheckerQueued = true\n\n\tqueueMicrotask(() => {\n\t\tcheckerQueued = false\n\n\t\t// If the refs are still equal, it means @reactive did not run (forgot\n\t\t// to decorate a class that uses @signal with @reactive).\n\t\tif (props === __propsToSignalify) {\n\t\t\tthrow new Error(\n\t\t\t\t// Array.from(map.keys()) instead of [...map.keys()] because it breaks in Oculus browser.\n\t\t\t\t`Stray @signal-decorated properties detected: ${Array.from(props.keys()).join(\n\t\t\t\t\t', ',\n\t\t\t\t)}. Did you forget to use the \\`@reactive\\` decorator on a class that has properties decorated with \\`@signal\\`?`,\n\t\t\t)\n\t\t}\n\t})\n}\n\nclass PropNotFoundError extends Error {\n\tconstructor(prop: PropertyKey) {\n\t\tsuper(\n\t\t\t`Property \"${String(\n\t\t\t\tprop,\n\t\t\t)}\" not found on instance of class decorated with \\`@reactive\\`. Did you forget to use the \\`@reactive\\` decorator on one of your classes that has a \"${String(\n\t\t\t\tprop,\n\t\t\t)}\" property decorated with \\`@signal\\`?`,\n\t\t)\n\t}\n}\n\nclass MissingDecoratorError extends Error {\n\tconstructor(prop: PropertyKey) {\n\t\tsuper(\n\t\t\t`Missing @signal decorator on setter or getter for property \"${String(\n\t\t\t\tprop,\n\t\t\t)}\". The @signal decorator will only work on a getter/setter pair with *both* getter and setter decorated with @signal.`,\n\t\t)\n\t}\n}\n\nclass InvalidDecorationError extends Error {\n\tconstructor() {\n\t\tsuper('The @signal decorator is only for use on fields, getters, setters, and auto accessors.')\n\t}\n}\n"],"mappings":"AAAA,SAAQA,MAAM,QAAO,UAAU;AAC/B,SAAQC,WAAW,EAAEC,yBAAyB,EAAEC,sBAAsB,EAAEC,cAAc,QAAO,yBAAyB;AAItH,OAAO,IAAIC,kBAAkB,GAAG,IAAIC,GAAG,CAAoB,CAAC;AAE5D,OAAO,SAASC,uBAAuBA,CAAA,EAAG;EACzCF,kBAAkB,GAAG,IAAIC,GAAG,CAAoB,CAAC;AAClD;AAEA,MAAME,SAAS,GAAGC,MAAM,CAAC,CAAC;AAI1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SA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QAAQ,CAAC;MAC9D,CAAC;IACF;EACD,CAAC,MAAM,MAAM,IAAIc,sBAAsB,CAAC,CAAC;AAC1C;AAEA,IAAIC,aAAa,GAAG,KAAK;;AAEzB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS7B,6BAA6BA,CAACH,KAA6B,EAAE;EACrE,IAAIgC,aAAa,EAAE;EACnBA,aAAa,GAAG,IAAI;EAEpBJ,cAAc,CAAC,MAAM;IACpBI,aAAa,GAAG,KAAK;;IAErB;IACA;IACA,IAAIhC,KAAK,KAAKX,kBAAkB,EAAE;MACjC,MAAM,IAAIa,KAAK;MACd;MACA,gDAAgD+B,KAAK,CAACC,IAAI,CAAClC,KAAK,CAACmC,IAAI,CAAC,CAAC,CAAC,CAACC,IAAI,CAC5E,IACD,CAAC,gHACF,CAAC;IACF;EACD,CAAC,CAAC;AACH;AAEA,MAAMvB,iBAAiB,SAASX,KAAK,CAAC;EACrCmC,WAAWA,CAAC5B,IAAiB,EAAE;IAC9B,KAAK,CACJ,aAAa6B,MAAM,CAClB7B,IACD,CAAC,uJAAuJ6B,MAAM,CAC7J7B,IACD,CAAC,wCACF,CAAC;EACF;AACD;AAEA,MAAMoB,qBAAqB,SAAS3B,KAAK,CAAC;EACzCmC,WAAWA,CAAC5B,IAAiB,EAAE;IAC9B,KAAK,CACJ,+DAA+D6B,MAAM,CACpE7B,IACD,CAAC,uHACF,CAAC;EACF;AACD;AAEA,MAAMsB,sBAAsB,SAAS7B,KAAK,CAAC;EAC1CmC,WAAWA,CAAA,EAAG;IACb,KAAK,CAAC,wFAAwF,CAAC;EAChG;AACD","ignoreList":[]} \ No newline at end of file diff --git a/dist/decorators/signal.test.js b/dist/decorators/signal.test.js index 001cd95..bebe24b 100644 --- a/dist/decorators/signal.test.js +++ b/dist/decorators/signal.test.js @@ -7,6 +7,7 @@ import { createEffect } from 'solid-js'; import { testButterflyProps } from '../index.test.js'; import { reactive } from './reactive.js'; import { signal } from './signal.js'; +import { signalify } from '../signals/signalify.js'; describe('classy-solid', () => { describe('@reactive, @signal', () => { let _initProto, _initClass, _init_colors, _init_extra_colors, _init_colors2, _init_extra_colors2, _init_wingSize, _init_extra_wingSize, _init_finalize, _init_extra_finalize, _initProto2, _init_colors3, _init_extra_colors3, _init_finalize2, _init_extra_finalize2, _init_colors4, _init_extra_colors4, _init_wingSize2, _init_extra_wingSize2, _init_finalize3, _init_extra_finalize3, _initClass2, _init_colors5, _init_extra_colors5, _init_wingSize3, _init_extra_wingSize3, _init_colors6, _get_colors, _set_colors, _init_extra_colors6, _initProto3, _call_colors, _call_colors2, _initProto4, _initProto5; @@ -459,6 +460,57 @@ describe('classy-solid', () => { expect(count).toBe(1); expect(b).toBe(b2); }); + it.only('prevents duplicate signals for any property', () => { + let _initProto7, _initClass10, _init_venomous, _init_extra_venomous, _init_legs, _init_extra_legs; + let _Insect3; + class Insect { + static { + ({ + e: [_init_legs, _init_extra_legs, _init_venomous, _init_extra_venomous, _initProto7], + c: [_Insect3, _initClass10] + } = _applyDecs(this, [reactive], [[signal, 0, "venomous"], [signal, 1, "legs"], [signal, 3, "eyes"], [signal, 4, "eyes"]])); + } + venomous = (_initProto7(this), _init_venomous(this, 0)); + #A = (_init_extra_venomous(this), _init_legs(this, 6)); + get legs() { + return this.#A; + } + set legs(v) { + this.#A = v; + } + #eyes = (_init_extra_legs(this), 10); + get eyes() { + return this.#eyes; + } + set eyes(n) { + this.#eyes = n; + } + antennas = 0; + constructor() { + // This should not add any extra signals for properties that + // are already signalified by the @signal decorator + signalify(this, 'venomous', 'legs', 'eyes', 'antennas'); + } + static { + _initClass10(); + } + } + const i = new _Insect3(); + testNoDuplicateSignal(i, 'venomous'); + testNoDuplicateSignal(i, 'legs'); + testNoDuplicateSignal(i, 'eyes'); + testNoDuplicateSignal(i, 'antennas'); + function testNoDuplicateSignal(o, prop) { + let count = 0; + createEffect(() => { + count++; + o[prop]; + }); + expect(count).toBe(1); + o[prop]++; + expect(count).toBe(2); // it would be 3 if there were an extra signal + } + }); }); }); //# sourceMappingURL=signal.test.js.map \ No newline at end of file diff --git a/dist/decorators/signal.test.js.map b/dist/decorators/signal.test.js.map index eacb7f2..b85cefc 100644 --- a/dist/decorators/signal.test.js.map +++ b/dist/decorators/signal.test.js.map @@ -1 +1 @@ -{"version":3,"file":"signal.test.js","names":["createEffect","testButterflyProps","reactive","signal","describe","_initProto","_initClass","_init_colors","_init_extra_colors","_init_colors2","_init_extra_colors2","_init_wingSize","_init_extra_wingSize","_init_finalize","_init_extra_finalize","_initProto2","_init_colors3","_init_extra_colors3","_init_finalize2","_init_extra_finalize2","_init_colors4","_init_extra_colors4","_init_wingSize2","_init_extra_wingSize2","_init_finalize3","_init_extra_finalize3","_initClass2","_init_colors5","_init_extra_colors5","_init_wingSize3","_init_extra_wingSize3","_init_colors6","_get_colors","_set_colors","_init_extra_colors6","_initProto3","_call_colors","_call_colors2","_initProto4","_initProto5","_Butterfly","Butterfly","e","c","_applyDecs","colors","wingSize","s","it","b","Butterfly2","o","finalize","v","_","constructor","Butterfly3","Butterfly4","A","_Butterfly2","Butterfly5","Butterfly6","#colors","getColors","setColors","testPrivate","Butterfly7","_colors","Base","Butterfly8","count","expect","toBe","ensure","_initClass3","_init_colors7","_init_extra_colors7","Mid","b0","testProp","Object","getOwnPropertyDescriptor","get","call","_SubButterfly","SubButterfly","args","m","value","SubSubButterfly","b2","k","startVal","newVal","_Insect2","_initClass4","_initProto6","_initClass5","_init_colors8","_init_extra_colors8","_Insect","Insect","double","_Butterfly3","arg","_init_foo","_init_extra_foo","_initClass6","_init_bar","_init_extra_bar","Foo","foo","_Bar","Bar","bar","toThrow","_initClass7","_init_do","_init_extra_do","_Doer","Doer","do","doer","newFunc","_Foo2","_initClass8","_init_amount","_init_extra_amount","_initClass9","_init_double","_init_extra_double","_Foo","amount","_Bar2","noLoop","not"],"sources":["../../src/decorators/signal.test.ts"],"sourcesContent":["import {createEffect} from 'solid-js'\nimport {testButterflyProps} from '../index.test.js'\nimport {reactive} from './reactive.js'\nimport {signal} from './signal.js'\n\ndescribe('classy-solid', () => {\n\tdescribe('@reactive, @signal', () => {\n\t\t@reactive\n\t\tclass Butterfly {\n\t\t\t@signal colors = 3\n\n\t\t\t#wingSize = 2\n\n\t\t\t@signal get wingSize() {\n\t\t\t\treturn this.#wingSize\n\t\t\t}\n\t\t\t@signal set wingSize(s: number) {\n\t\t\t\tthis.#wingSize = s\n\t\t\t}\n\t\t}\n\n\t\tit('makes class fields reactive, using class and field/getter/setter decorators', () => {\n\t\t\tconst b = new Butterfly()\n\n\t\t\ttestButterflyProps(b)\n\t\t})\n\n\t\t// @reactive\n\t\tclass Butterfly2 {\n\t\t\t@signal colors = 3\n\t\t\t@signal wingSize = 2\n\t\t\t// @ts-ignore\n\t\t\t@signal #finalize\n\t\t}\n\n\t\tit('makes class fields reactive, using field decorators without class decorator', () => {\n\t\t\tconst b = new Butterfly2()\n\n\t\t\ttestButterflyProps(b)\n\t\t})\n\n\t\tclass Butterfly3 {\n\t\t\t@signal colors = 3\n\n\t\t\t#wingSize = 2\n\n\t\t\t@signal get wingSize() {\n\t\t\t\treturn this.#wingSize\n\t\t\t}\n\t\t\t@signal set wingSize(s: number) {\n\t\t\t\tthis.#wingSize = s\n\t\t\t}\n\n\t\t\t// @ts-ignore\n\t\t\t@signal #finalize\n\t\t}\n\n\t\tit('makes class fields reactive, using field/getter/setter decorators without class decorator', () => {\n\t\t\tconst b = new Butterfly3()\n\n\t\t\ttestButterflyProps(b)\n\t\t})\n\n\t\tclass Butterfly4 {\n\t\t\t@signal colors = 3\n\t\t\t@signal accessor wingSize = 2\n\t\t\t// @ts-ignore\n\t\t\t@signal #finalize\n\t\t}\n\n\t\tit('makes class fields reactive, using field/accessor decorators without class decorator', () => {\n\t\t\tconst b = new Butterfly4()\n\n\t\t\ttestButterflyProps(b)\n\t\t})\n\n\t\t@reactive\n\t\tclass Butterfly5 {\n\t\t\t@signal colors = 3\n\t\t\t@signal accessor wingSize = 2\n\t\t}\n\n\t\tit('makes class fields reactive, using field/accessor decorators with class decorator', () => {\n\t\t\tconst b = new Butterfly5()\n\n\t\t\ttestButterflyProps(b)\n\t\t})\n\n\t\tclass Butterfly6 {\n\t\t\t@signal accessor #colors = 3\n\n\t\t\tgetColors() {\n\t\t\t\treturn this.#colors\n\t\t\t}\n\t\t\tsetColors(v: number) {\n\t\t\t\treturn (this.#colors = v)\n\t\t\t}\n\t\t}\n\n\t\tit('makes private class auto accessor reactive', () => {\n\t\t\tconst b = new Butterfly6()\n\t\t\ttestPrivate(b)\n\t\t})\n\n\t\tclass Butterfly7 {\n\t\t\t#_colors = 3\n\n\t\t\t@signal get #colors() {\n\t\t\t\treturn this.#_colors\n\t\t\t}\n\t\t\t@signal set #colors(v: number) {\n\t\t\t\tthis.#_colors = v\n\t\t\t}\n\n\t\t\tgetColors() {\n\t\t\t\treturn this.#colors\n\t\t\t}\n\t\t\tsetColors(v: number) {\n\t\t\t\treturn (this.#colors = v)\n\t\t\t}\n\t\t}\n\n\t\tit('makes private class getter/setter accessors reactive', () => {\n\t\t\tconst b = new Butterfly7()\n\t\t\ttestPrivate(b)\n\t\t})\n\n\t\tclass Base {\n\t\t\t#colors = 3\n\n\t\t\t@signal get colors() {\n\t\t\t\treturn this.#colors\n\t\t\t}\n\t\t\t@signal set colors(v: number) {\n\t\t\t\tthis.#colors = v\n\t\t\t}\n\t\t}\n\n\t\tclass Butterfly8 extends Base {\n\t\t\t#colors = 3\n\n\t\t\t@signal override get colors() {\n\t\t\t\treturn this.#colors\n\t\t\t}\n\t\t\t@signal override set colors(v: number) {\n\t\t\t\tthis.#colors = v\n\t\t\t}\n\n\t\t\tgetColors() {\n\t\t\t\treturn this.colors\n\t\t\t}\n\t\t\tsetColors(v: number) {\n\t\t\t\treturn (this.colors = v)\n\t\t\t}\n\t\t}\n\n\t\tit('makes overridden class getter/setter accessors reactive', () => {\n\t\t\tconst b = new Butterfly8()\n\t\t\ttestPrivate(b)\n\t\t})\n\n\t\tfunction testPrivate(b: Pick) {\n\t\t\tlet count = 0\n\n\t\t\tcreateEffect(() => {\n\t\t\t\tb.getColors()\n\t\t\t\tcount++\n\t\t\t})\n\n\t\t\texpect(b.getColors()).toBe(3)\n\t\t\texpect(count).toBe(1)\n\n\t\t\tb.setColors(5)\n\t\t\texpect(b.getColors()).toBe(5)\n\t\t\texpect(count).toBe(2)\n\t\t}\n\n\t\tconst ensure = it\n\n\t\tensure('overridden fields work as expected', async () => {\n\t\t\tclass Mid extends Butterfly {\n\t\t\t\toverride colors = 0\n\t\t\t}\n\n\t\t\t// ensure subclass did not interfere with functionality of base class\n\t\t\tconst b0 = new Butterfly()\n\t\t\ttestProp(b0, 'colors', 3, 4, true)\n\t\t\texpect(Object.getOwnPropertyDescriptor(b0, 'colors')?.get?.call(b0) === 4).toBe(true) // accessor descriptor\n\n\t\t\t@reactive\n\t\t\tclass SubButterfly extends Mid {\n\t\t\t\t@signal override colors = 123\n\t\t\t}\n\n\t\t\t// ensure subclass did not interfere with functionality of base class\n\t\t\tconst m = new Mid()\n\t\t\ttestProp(m, 'colors', 0, 1, false)\n\t\t\texpect(Object.getOwnPropertyDescriptor(m, 'colors')?.value === 1).toBe(true) // value descriptor\n\n\t\t\tclass SubSubButterfly extends SubButterfly {\n\t\t\t\toverride colors = 456\n\t\t\t}\n\n\t\t\tconst b = new SubButterfly()\n\t\t\ttestButterflyProps(b, 123)\n\n\t\t\tconst b2 = new SubSubButterfly()\n\n\t\t\ttestProp(b2, 'colors', 456, 654, false)\n\t\t})\n\n\t\tfunction testProp(o: T, k: keyof T, startVal: any, newVal: any, reactive = true) {\n\t\t\tlet count = 0\n\n\t\t\tcreateEffect(() => {\n\t\t\t\to[k]\n\t\t\t\tcount++\n\t\t\t})\n\n\t\t\texpect(o[k]).toBe(startVal)\n\t\t\texpect(count).toBe(1)\n\n\t\t\to[k] = newVal // should not be a signal, should not trigger\n\n\t\t\texpect(o[k]).toBe(newVal)\n\t\t\texpect(count).toBe(reactive ? 2 : 1)\n\t\t}\n\n\t\tit('does not prevent superclass constructor from receiving subclass constructor args', () => {\n\t\t\t@reactive\n\t\t\tclass Insect {\n\t\t\t\tconstructor(public double: number) {}\n\t\t\t}\n\n\t\t\t@reactive\n\t\t\tclass Butterfly extends Insect {\n\t\t\t\t@signal colors = 3\n\n\t\t\t\t#wingSize = 2\n\n\t\t\t\t@signal get wingSize() {\n\t\t\t\t\treturn this.#wingSize\n\t\t\t\t}\n\t\t\t\t@signal set wingSize(s: number) {\n\t\t\t\t\tthis.#wingSize = s\n\t\t\t\t}\n\n\t\t\t\tconstructor(arg: number) {\n\t\t\t\t\tsuper(arg * 2)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst b = new Butterfly(4)\n\n\t\t\texpect(b.double).toBe(8)\n\t\t\ttestButterflyProps(b)\n\t\t})\n\n\t\tit('throws an error when @signal is used without @reactive', async () => {\n\t\t\texpect(() => {\n\t\t\t\t// user forgot to use @reactive here\n\t\t\t\tclass Foo {\n\t\t\t\t\t@signal foo = 'hoo'\n\t\t\t\t}\n\n\t\t\t\tFoo\n\n\t\t\t\t@reactive\n\t\t\t\tclass Bar {\n\t\t\t\t\t@signal bar = 123\n\t\t\t\t}\n\n\t\t\t\tnew Bar()\n\t\t\t}).toThrow('Did you forget')\n\n\t\t\t// TODO how to check for an error thrown from a microtask?\n\t\t\t// (window.addEventListener('error') seems not to work)\n\t\t\t//\n\t\t\t// It just won't work, the error seems to never fire here in the\n\t\t\t// tests, but it works fine when testing manually in Chrome.\n\n\t\t\t// const errPromise = new Promise(r => window.addEventListener('error', e => r(e), {once: true}))\n\n\t\t\t// @reactive\n\t\t\t// class Foo {\n\t\t\t// \t@signal foo = 'hoo'\n\t\t\t// }\n\n\t\t\t// Foo\n\n\t\t\t// // user forgot to use @reactive here\n\t\t\t// class Bar {\n\t\t\t// \t@signal bar = 123\n\t\t\t// }\n\n\t\t\t// Bar\n\n\t\t\t// const err = await errPromise\n\n\t\t\t// expect(err.message).toContain('Did you forget')\n\t\t})\n\n\t\tit('works with function values', () => {\n\t\t\t// This test ensures that functions are handled propertly, because\n\t\t\t// if passed without being wrapped to a signal setter it will be\n\t\t\t// called immediately with the previous value and be expected to\n\t\t\t// return a new value, instead of being set as the actual new value.\n\n\t\t\t@reactive\n\t\t\tclass Doer {\n\t\t\t\t@signal do: (() => unknown) | null = null\n\t\t\t}\n\n\t\t\tconst doer = new Doer()\n\n\t\t\texpect(doer.do).toBe(null)\n\n\t\t\tconst newFunc = () => 123\n\t\t\tdoer.do = newFunc\n\n\t\t\texpect(doer.do).toBe(newFunc)\n\t\t\texpect(doer.do()).toBe(123)\n\t\t})\n\n\t\tit('automatically does not track reactivity in constructors when using decorators', () => {\n\t\t\t@reactive\n\t\t\tclass Foo {\n\t\t\t\t@signal amount = 3\n\t\t\t}\n\n\t\t\t@reactive\n\t\t\tclass Bar extends Foo {\n\t\t\t\t@signal double = 0\n\n\t\t\t\tconstructor() {\n\t\t\t\t\tsuper()\n\t\t\t\t\tthis.double = this.amount * 2 // this read of .amount should not be tracked\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet b: Bar\n\t\t\tlet count = 0\n\n\t\t\tfunction noLoop() {\n\t\t\t\tcreateEffect(() => {\n\t\t\t\t\tb = new Bar() // this should not track\n\t\t\t\t\tcount++\n\t\t\t\t})\n\t\t\t}\n\n\t\t\texpect(noLoop).not.toThrow()\n\n\t\t\tconst b2 = b!\n\n\t\t\tb!.amount = 4 // hence this should not trigger\n\n\t\t\t// If the effect ran only once initially, not when setting b.colors,\n\t\t\t// then both variables should reference the same instance\n\t\t\texpect(count).toBe(1)\n\t\t\texpect(b!).toBe(b2)\n\t\t})\n\t})\n})\n"],"mappings":";;;;;AAAA,SAAQA,YAAY,QAAO,UAAU;AACrC,SAAQC,kBAAkB,QAAO,kBAAkB;AACnD,SAAQC,QAAQ,QAAO,eAAe;AACtC,SAAQC,MAAM,QAAO,aAAa;AAElCC,QAAQ,CAAC,cAAc,EAAE,MAAM;EAC9BA,Q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AE5B,MAAMzB,EAAE,GAAGzC,CAAE;MAEbA,CAAC,CAAEmF,MAAM,GAAG,CAAC,EAAC;;MAEd;MACA;MACA7D,MAAM,CAACD,KAAK,CAAC,CAACE,IAAI,CAAC,CAAC,CAAC;MACrBD,MAAM,CAACtB,CAAE,CAAC,CAACuB,IAAI,CAACkB,EAAE,CAAC;IACpB,CAAC,CAAC;EACH,CAAC,CAAC;AACH,CAAC,CAAC","ignoreList":[]} \ No newline at end of file +{"version":3,"file":"signal.test.js","names":["createEffect","testButterflyProps","reactive","signal","signalify","describe","_initProto","_initClass","_init_colors","_init_extra_colors","_init_colors2","_init_extra_colors2","_init_wingSize","_init_extra_wingSize","_init_finalize","_init_extra_finalize","_initProto2","_init_colors3","_init_extra_colors3","_init_finalize2","_init_extra_finalize2","_init_colors4","_init_extra_colors4","_init_wingSize2","_init_extra_wingSize2","_init_finalize3","_init_extra_finalize3","_initClass2","_init_colors5","_init_extra_colors5","_init_wingSize3","_init_extra_wingSize3","_init_colors6","_get_colors","_set_colors","_init_extra_colors6","_initProto3","_call_colors","_call_colors2","_initProto4","_initProto5","_Butterfly","Butterfly","e","c","_applyDecs","colors","wingSize","s","it","b","Butterfly2","o","finalize","v","_","constructor","Butterfly3","Butterfly4","A","_Butterfly2","Butterfly5","Butterfly6","#colors","getColors","setColors","testPrivate","Butterfly7","_colors","Base","Butterfly8","count","expect","toBe","ensure","_initClass3","_init_colors7","_init_extra_colors7","Mid","b0","testProp","Object","getOwnPropertyDescriptor","get","call","_SubButterfly","SubButterfly","args","m","value","SubSubButterfly","b2","k","startVal","newVal","_Insect2","_initClass4","_initProto6","_initClass5","_init_colors8","_init_extra_colors8","_Insect","Insect","double","_Butterfly3","arg","_init_foo","_init_extra_foo","_initClass6","_init_bar","_init_extra_bar","Foo","foo","_Bar","Bar","bar","toThrow","_initClass7","_init_do","_init_extra_do","_Doer","Doer","do","doer","newFunc","_Foo2","_initClass8","_init_amount","_init_extra_amount","_initClass9","_init_double","_init_extra_double","_Foo","amount","_Bar2","noLoop","not","only","_initProto7","_initClass10","_init_venomous","_init_extra_venomous","_init_legs","_init_extra_legs","_Insect3","venomous","legs","eyes","n","antennas","i","testNoDuplicateSignal","prop"],"sources":["../../src/decorators/signal.test.ts"],"sourcesContent":["import {createEffect} from 'solid-js'\nimport {testButterflyProps} from '../index.test.js'\nimport {reactive} from './reactive.js'\nimport {signal} from './signal.js'\nimport {signalify} from '../signals/signalify.js'\n\ndescribe('classy-solid', () => {\n\tdescribe('@reactive, @signal', () => {\n\t\t@reactive\n\t\tclass Butterfly {\n\t\t\t@signal colors = 3\n\n\t\t\t#wingSize = 2\n\n\t\t\t@signal get wingSize() {\n\t\t\t\treturn this.#wingSize\n\t\t\t}\n\t\t\t@signal set wingSize(s: number) {\n\t\t\t\tthis.#wingSize = s\n\t\t\t}\n\t\t}\n\n\t\tit('makes class fields reactive, using class and field/getter/setter decorators', () => {\n\t\t\tconst b = new Butterfly()\n\n\t\t\ttestButterflyProps(b)\n\t\t})\n\n\t\t// @reactive\n\t\tclass Butterfly2 {\n\t\t\t@signal colors = 3\n\t\t\t@signal wingSize = 2\n\t\t\t// @ts-ignore\n\t\t\t@signal #finalize\n\t\t}\n\n\t\tit('makes class fields reactive, using field decorators without class decorator', () => {\n\t\t\tconst b = new Butterfly2()\n\n\t\t\ttestButterflyProps(b)\n\t\t})\n\n\t\tclass Butterfly3 {\n\t\t\t@signal colors = 3\n\n\t\t\t#wingSize = 2\n\n\t\t\t@signal get wingSize() {\n\t\t\t\treturn this.#wingSize\n\t\t\t}\n\t\t\t@signal set wingSize(s: number) {\n\t\t\t\tthis.#wingSize = s\n\t\t\t}\n\n\t\t\t// @ts-ignore\n\t\t\t@signal #finalize\n\t\t}\n\n\t\tit('makes class fields reactive, using field/getter/setter decorators without class decorator', () => {\n\t\t\tconst b = new Butterfly3()\n\n\t\t\ttestButterflyProps(b)\n\t\t})\n\n\t\tclass Butterfly4 {\n\t\t\t@signal colors = 3\n\t\t\t@signal accessor wingSize = 2\n\t\t\t// @ts-ignore\n\t\t\t@signal #finalize\n\t\t}\n\n\t\tit('makes class fields reactive, using field/accessor decorators without class decorator', () => {\n\t\t\tconst b = new Butterfly4()\n\n\t\t\ttestButterflyProps(b)\n\t\t})\n\n\t\t@reactive\n\t\tclass Butterfly5 {\n\t\t\t@signal colors = 3\n\t\t\t@signal accessor wingSize = 2\n\t\t}\n\n\t\tit('makes class fields reactive, using field/accessor decorators with class decorator', () => {\n\t\t\tconst b = new Butterfly5()\n\n\t\t\ttestButterflyProps(b)\n\t\t})\n\n\t\tclass Butterfly6 {\n\t\t\t@signal accessor #colors = 3\n\n\t\t\tgetColors() {\n\t\t\t\treturn this.#colors\n\t\t\t}\n\t\t\tsetColors(v: number) {\n\t\t\t\treturn (this.#colors = v)\n\t\t\t}\n\t\t}\n\n\t\tit('makes private class auto accessor reactive', () => {\n\t\t\tconst b = new Butterfly6()\n\t\t\ttestPrivate(b)\n\t\t})\n\n\t\tclass Butterfly7 {\n\t\t\t#_colors = 3\n\n\t\t\t@signal get #colors() {\n\t\t\t\treturn this.#_colors\n\t\t\t}\n\t\t\t@signal set #colors(v: number) {\n\t\t\t\tthis.#_colors = v\n\t\t\t}\n\n\t\t\tgetColors() {\n\t\t\t\treturn this.#colors\n\t\t\t}\n\t\t\tsetColors(v: number) {\n\t\t\t\treturn (this.#colors = v)\n\t\t\t}\n\t\t}\n\n\t\tit('makes private class getter/setter accessors reactive', () => {\n\t\t\tconst b = new Butterfly7()\n\t\t\ttestPrivate(b)\n\t\t})\n\n\t\tclass Base {\n\t\t\t#colors = 3\n\n\t\t\t@signal get colors() {\n\t\t\t\treturn this.#colors\n\t\t\t}\n\t\t\t@signal set colors(v: number) {\n\t\t\t\tthis.#colors = v\n\t\t\t}\n\t\t}\n\n\t\tclass Butterfly8 extends Base {\n\t\t\t#colors = 3\n\n\t\t\t@signal override get colors() {\n\t\t\t\treturn this.#colors\n\t\t\t}\n\t\t\t@signal override set colors(v: number) {\n\t\t\t\tthis.#colors = v\n\t\t\t}\n\n\t\t\tgetColors() {\n\t\t\t\treturn this.colors\n\t\t\t}\n\t\t\tsetColors(v: number) {\n\t\t\t\treturn (this.colors = v)\n\t\t\t}\n\t\t}\n\n\t\tit('makes overridden class getter/setter accessors reactive', () => {\n\t\t\tconst b = new Butterfly8()\n\t\t\ttestPrivate(b)\n\t\t})\n\n\t\tfunction testPrivate(b: Pick) {\n\t\t\tlet count = 0\n\n\t\t\tcreateEffect(() => {\n\t\t\t\tb.getColors()\n\t\t\t\tcount++\n\t\t\t})\n\n\t\t\texpect(b.getColors()).toBe(3)\n\t\t\texpect(count).toBe(1)\n\n\t\t\tb.setColors(5)\n\t\t\texpect(b.getColors()).toBe(5)\n\t\t\texpect(count).toBe(2)\n\t\t}\n\n\t\tconst ensure = it\n\n\t\tensure('overridden fields work as expected', async () => {\n\t\t\tclass Mid extends Butterfly {\n\t\t\t\toverride colors = 0\n\t\t\t}\n\n\t\t\t// ensure subclass did not interfere with functionality of base class\n\t\t\tconst b0 = new Butterfly()\n\t\t\ttestProp(b0, 'colors', 3, 4, true)\n\t\t\texpect(Object.getOwnPropertyDescriptor(b0, 'colors')?.get?.call(b0) === 4).toBe(true) // accessor descriptor\n\n\t\t\t@reactive\n\t\t\tclass SubButterfly extends Mid {\n\t\t\t\t@signal override colors = 123\n\t\t\t}\n\n\t\t\t// ensure subclass did not interfere with functionality of base class\n\t\t\tconst m = new Mid()\n\t\t\ttestProp(m, 'colors', 0, 1, false)\n\t\t\texpect(Object.getOwnPropertyDescriptor(m, 'colors')?.value === 1).toBe(true) // value descriptor\n\n\t\t\tclass SubSubButterfly extends SubButterfly {\n\t\t\t\toverride colors = 456\n\t\t\t}\n\n\t\t\tconst b = new SubButterfly()\n\t\t\ttestButterflyProps(b, 123)\n\n\t\t\tconst b2 = new SubSubButterfly()\n\n\t\t\ttestProp(b2, 'colors', 456, 654, false)\n\t\t})\n\n\t\tfunction testProp(o: T, k: keyof T, startVal: any, newVal: any, reactive = true) {\n\t\t\tlet count = 0\n\n\t\t\tcreateEffect(() => {\n\t\t\t\to[k]\n\t\t\t\tcount++\n\t\t\t})\n\n\t\t\texpect(o[k]).toBe(startVal)\n\t\t\texpect(count).toBe(1)\n\n\t\t\to[k] = newVal // should not be a signal, should not trigger\n\n\t\t\texpect(o[k]).toBe(newVal)\n\t\t\texpect(count).toBe(reactive ? 2 : 1)\n\t\t}\n\n\t\tit('does not prevent superclass constructor from receiving subclass constructor args', () => {\n\t\t\t@reactive\n\t\t\tclass Insect {\n\t\t\t\tconstructor(public double: number) {}\n\t\t\t}\n\n\t\t\t@reactive\n\t\t\tclass Butterfly extends Insect {\n\t\t\t\t@signal colors = 3\n\n\t\t\t\t#wingSize = 2\n\n\t\t\t\t@signal get wingSize() {\n\t\t\t\t\treturn this.#wingSize\n\t\t\t\t}\n\t\t\t\t@signal set wingSize(s: number) {\n\t\t\t\t\tthis.#wingSize = s\n\t\t\t\t}\n\n\t\t\t\tconstructor(arg: number) {\n\t\t\t\t\tsuper(arg * 2)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst b = new Butterfly(4)\n\n\t\t\texpect(b.double).toBe(8)\n\t\t\ttestButterflyProps(b)\n\t\t})\n\n\t\tit('throws an error when @signal is used without @reactive', async () => {\n\t\t\texpect(() => {\n\t\t\t\t// user forgot to use @reactive here\n\t\t\t\tclass Foo {\n\t\t\t\t\t@signal foo = 'hoo'\n\t\t\t\t}\n\n\t\t\t\tFoo\n\n\t\t\t\t@reactive\n\t\t\t\tclass Bar {\n\t\t\t\t\t@signal bar = 123\n\t\t\t\t}\n\n\t\t\t\tnew Bar()\n\t\t\t}).toThrow('Did you forget')\n\n\t\t\t// TODO how to check for an error thrown from a microtask?\n\t\t\t// (window.addEventListener('error') seems not to work)\n\t\t\t//\n\t\t\t// It just won't work, the error seems to never fire here in the\n\t\t\t// tests, but it works fine when testing manually in Chrome.\n\n\t\t\t// const errPromise = new Promise(r => window.addEventListener('error', e => r(e), {once: true}))\n\n\t\t\t// @reactive\n\t\t\t// class Foo {\n\t\t\t// \t@signal foo = 'hoo'\n\t\t\t// }\n\n\t\t\t// Foo\n\n\t\t\t// // user forgot to use @reactive here\n\t\t\t// class Bar {\n\t\t\t// \t@signal bar = 123\n\t\t\t// }\n\n\t\t\t// Bar\n\n\t\t\t// const err = await errPromise\n\n\t\t\t// expect(err.message).toContain('Did you forget')\n\t\t})\n\n\t\tit('works with function values', () => {\n\t\t\t// This test ensures that functions are handled propertly, because\n\t\t\t// if passed without being wrapped to a signal setter it will be\n\t\t\t// called immediately with the previous value and be expected to\n\t\t\t// return a new value, instead of being set as the actual new value.\n\n\t\t\t@reactive\n\t\t\tclass Doer {\n\t\t\t\t@signal do: (() => unknown) | null = null\n\t\t\t}\n\n\t\t\tconst doer = new Doer()\n\n\t\t\texpect(doer.do).toBe(null)\n\n\t\t\tconst newFunc = () => 123\n\t\t\tdoer.do = newFunc\n\n\t\t\texpect(doer.do).toBe(newFunc)\n\t\t\texpect(doer.do()).toBe(123)\n\t\t})\n\n\t\tit('automatically does not track reactivity in constructors when using decorators', () => {\n\t\t\t@reactive\n\t\t\tclass Foo {\n\t\t\t\t@signal amount = 3\n\t\t\t}\n\n\t\t\t@reactive\n\t\t\tclass Bar extends Foo {\n\t\t\t\t@signal double = 0\n\n\t\t\t\tconstructor() {\n\t\t\t\t\tsuper()\n\t\t\t\t\tthis.double = this.amount * 2 // this read of .amount should not be tracked\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet b: Bar\n\t\t\tlet count = 0\n\n\t\t\tfunction noLoop() {\n\t\t\t\tcreateEffect(() => {\n\t\t\t\t\tb = new Bar() // this should not track\n\t\t\t\t\tcount++\n\t\t\t\t})\n\t\t\t}\n\n\t\t\texpect(noLoop).not.toThrow()\n\n\t\t\tconst b2 = b!\n\n\t\t\tb!.amount = 4 // hence this should not trigger\n\n\t\t\t// If the effect ran only once initially, not when setting b.colors,\n\t\t\t// then both variables should reference the same instance\n\t\t\texpect(count).toBe(1)\n\t\t\texpect(b!).toBe(b2)\n\t\t})\n\n\t\tit.only('prevents duplicate signals for any property', () => {\n\t\t\t@reactive\n\t\t\tclass Insect {\n\t\t\t\t@signal venomous = 0\n\n\t\t\t\t@signal accessor legs = 6\n\n\t\t\t\t#eyes = 10\n\t\t\t\t@signal get eyes() {\n\t\t\t\t\treturn this.#eyes\n\t\t\t\t}\n\t\t\t\t@signal set eyes(n) {\n\t\t\t\t\tthis.#eyes = n\n\t\t\t\t}\n\n\t\t\t\tantennas = 0\n\n\t\t\t\tconstructor() {\n\t\t\t\t\t// This should not add any extra signals for properties that\n\t\t\t\t\t// are already signalified by the @signal decorator\n\t\t\t\t\tsignalify(this, 'venomous', 'legs', 'eyes', 'antennas')\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst i = new Insect()\n\n\t\t\ttestNoDuplicateSignal(i, 'venomous')\n\t\t\ttestNoDuplicateSignal(i, 'legs')\n\t\t\ttestNoDuplicateSignal(i, 'eyes')\n\t\t\ttestNoDuplicateSignal(i, 'antennas')\n\n\t\t\tfunction testNoDuplicateSignal(o: Insect, prop: keyof Insect) {\n\t\t\t\tlet count = 0\n\t\t\t\tcreateEffect(() => {\n\t\t\t\t\tcount++\n\t\t\t\t\to[prop]\n\t\t\t\t})\n\t\t\t\texpect(count).toBe(1)\n\t\t\t\to[prop]++\n\t\t\t\texpect(count).toBe(2) // it would be 3 if there were an extra signal\n\t\t\t}\n\t\t})\n\t})\n})\n"],"mappings":";;;;;AAAA,SAAQA,YAAY,QAAO,UAAU;AACrC,SAAQC,kBAAkB,QAAO,kBAAkB;AACnD,SAAQC,QAAQ,QAAO,eAAe;AACtC,SAAQC,MAAM,QAAO,aAAa;AAClC,SAAQC,SAAS,QAAO,yBAAyB;AAEjDC,QAAQ,CAAC,cAAc,EAAE,MAAM;EAC9BA,QAAQ,CAAC,oBAAoB,EAAE,MAAM;IAAA,IAAAC,UAAA,EAAAC,UAAA,EAAAC,YAAA,EAAAC,kBAAA,EAA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C,CAAC;MAEtBiD,qBAAqB,CAACD,CAAC,EAAE,UAAU,CAAC;MACpCC,qBAAqB,CAACD,CAAC,EAAE,MAAM,CAAC;MAChCC,qBAAqB,CAACD,CAAC,EAAE,MAAM,CAAC;MAChCC,qBAAqB,CAACD,CAAC,EAAE,UAAU,CAAC;MAEpC,SAASC,qBAAqBA,CAACnG,CAAS,EAAEoG,IAAkB,EAAE;QAC7D,IAAIjF,KAAK,GAAG,CAAC;QACbvE,YAAY,CAAC,MAAM;UAClBuE,KAAK,EAAE;UACPnB,CAAC,CAACoG,IAAI,CAAC;QACR,CAAC,CAAC;QACFhF,MAAM,CAACD,KAAK,CAAC,CAACE,IAAI,CAAC,CAAC,CAAC;QACrBrB,CAAC,CAACoG,IAAI,CAAC,EAAE;QACThF,MAAM,CAACD,KAAK,CAAC,CAACE,IAAI,CAAC,CAAC,CAAC,EAAC;MACvB;IACD,CAAC,CAAC;EACH,CAAC,CAAC;AACH,CAAC,CAAC","ignoreList":[]} \ No newline at end of file diff --git a/dist/signals/signalify.d.ts b/dist/signals/signalify.d.ts index e8b4b8a..bef1733 100644 --- a/dist/signals/signalify.d.ts +++ b/dist/signals/signalify.d.ts @@ -53,6 +53,7 @@ export declare function signalify(obj: T, ...props: (keyof T)[ export declare function signalify(obj: T, ...props: [key: keyof T, initialValue: unknown][]): T; export declare function __isPropSetAtLeastOnce(instance: object, prop: string | symbol): boolean; export declare function __trackPropSetAtLeastOnce(instance: object, prop: string | symbol): void; +export declare const isSignalGetter: WeakSet; export declare function __createSignalAccessor(obj: T, prop: Exclude, initialVal: unknown): void; export declare function __getSignal(obj: object, storage: WeakMap>, initialVal: unknown): SignalFunction; //# sourceMappingURL=signalify.d.ts.map \ No newline at end of file diff --git a/dist/signals/signalify.d.ts.map b/dist/signals/signalify.d.ts.map index 5461150..c9aaae9 100644 --- a/dist/signals/signalify.d.ts.map +++ b/dist/signals/signalify.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"signalify.d.ts","sourceRoot":"","sources":["../../src/signals/signalify.ts"],"names":[],"mappings":"AAGA,OAAO,EAAuB,KAAK,cAAc,EAAC,MAAM,2BAA2B,CAAA;AAInF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAA;AACzE,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;AAC7E,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,GAAG,CAAC,CAAA;AA+BzG,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,WAE7E;AAED,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,QAGhF;AAID,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,MAAM,EACtD,GAAG,EAAE,CAAC,EACN,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,EAC9B,UAAU,EAAE,OAAO,GACjB,IAAI,CA2DN;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,2BAI9G"} \ No newline at end of file +{"version":3,"file":"signalify.d.ts","sourceRoot":"","sources":["../../src/signals/signalify.ts"],"names":[],"mappings":"AAGA,OAAO,EAAuB,KAAK,cAAc,EAAC,MAAM,2BAA2B,CAAA;AAInF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAA;AACzE,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;AAC7E,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,GAAG,CAAC,CAAA;AA+BzG,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,WAE7E;AAED,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,QAGhF;AAED,eAAO,MAAM,cAAc,mBAA0B,CAAA;AAErD,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,MAAM,EACtD,GAAG,EAAE,CAAC,EACN,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,EAC9B,UAAU,EAAE,OAAO,GACjB,IAAI,CA2DN;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,2BAI9G"} \ No newline at end of file diff --git a/dist/signals/signalify.js b/dist/signals/signalify.js index 2251651..43ab24e 100644 --- a/dist/signals/signalify.js +++ b/dist/signals/signalify.js @@ -86,7 +86,7 @@ export function __trackPropSetAtLeastOnce(instance, prop) { if (!propsSetAtLeastOnce.has(instance)) propsSetAtLeastOnce.set(instance, new Set()); propsSetAtLeastOnce.get(instance).add(prop); } -const isSignalGetter = new WeakSet(); +export const isSignalGetter = new WeakSet(); export function __createSignalAccessor(obj, prop, initialVal) { let descriptor = getInheritedDescriptor(obj, prop); let originalGet; diff --git a/dist/signals/signalify.js.map b/dist/signals/signalify.js.map index a5ab732..db71a8a 100644 --- a/dist/signals/signalify.js.map +++ b/dist/signals/signalify.js.map @@ -1 +1 @@ -{"version":3,"file":"signalify.js","names":["getInheritedDescriptor","$PROXY","untrack","createSignalFunction","signalify","obj","props","proxy","_props","length","Object","keys","concat","getOwnPropertySymbols","prop","isTuple","Array","isArray","_prop","initialValue","__createSignalAccessor","propsSetAtLeastOnce","WeakMap","__isPropSetAtLeastOnce","instance","get","has","__trackPropSetAtLeastOnce","set","Set","add","isSignalGetter","WeakSet","initialVal","descriptor","originalGet","originalSet","isAccessor","warnNotReadWrite","writable","warnNotWritable","value","signalStorage","newDescriptor","configurable","enumerable","__getSignal","call","newValue","s","defineProperty","storage","equals","console","warn","String"],"sources":["../../src/signals/signalify.ts"],"sourcesContent":["import {getInheritedDescriptor} from 'lowclass/dist/getInheritedDescriptor.js'\nimport {$PROXY, untrack} from 'solid-js'\nimport type {PropKey} from '../decorators/types.js'\nimport {createSignalFunction, type SignalFunction} from './createSignalFunction.js'\n\ntype AnyObject = Record\n\n/**\n * Convert properties on an object into Solid signal-backed properties.\n *\n * There are two ways to use this: either by defining which properties to\n * convert to signal-backed properties by providing an array as property names\n * in the second arg, which is useful on plain objects, or by passing in `this`\n * and `this.constructor` within the `constructor` of a class that has\n * properties decorated with `@signal`.\n *\n * Example with a class:\n *\n * ```js\n * import {signalify} from 'classy-solid'\n * import {createEffect} from 'solid-js'\n *\n * class Counter {\n * count = 0\n *\n * constructor() {\n * signalify(this, 'count')\n * setInterval(() => this.count++, 1000)\n * }\n * }\n *\n * const counter = new Counter\n *\n * createEffect(() => {\n * console.log('count:', counter.count)\n * })\n * ```\n *\n * Example with a plain object:\n *\n * ```js\n * import {signalify} from 'classy-solid'\n * import {createEffect} from 'solid-js'\n *\n * const counter = {\n * count: 0\n * }\n *\n * signalify(counter, 'count')\n * setInterval(() => counter.count++, 1000)\n *\n * createEffect(() => {\n * console.log('count:', counter.count)\n * })\n * ```\n */\nexport function signalify(obj: T): T\nexport function signalify(obj: T, ...props: (keyof T)[]): T\nexport function signalify(obj: T, ...props: [key: keyof T, initialValue: unknown][]): T\nexport function signalify(obj: AnyObject, ...props: [key: PropertyKey, initialValue: unknown][] | PropertyKey[]) {\n\t// Special case for Solid proxies: if the object is already a solid proxy,\n\t// all properties are already reactive, no need to signalify.\n\t// @ts-expect-error special indexed access\n\tconst proxy = obj[$PROXY] as T\n\tif (proxy) return obj\n\n\tconst _props = props.length ? props : (Object.keys(obj) as PropKey[]).concat(Object.getOwnPropertySymbols(obj))\n\n\t// Use `untrack` here to be extra safe the initial value doesn't count as a\n\t// dependency and cause a reactivity loop.\n\tfor (const prop of _props) {\n\t\tconst isTuple = Array.isArray(prop)\n\t\t// We cast from PropertyKey to PropKey because keys can't actually be number, only string | symbol.\n\t\tconst _prop = (isTuple ? prop[0] : prop) as PropKey\n\t\tconst initialValue = isTuple ? prop[1] : untrack(() => obj[_prop])\n\n\t\t__createSignalAccessor(obj, _prop, initialValue)\n\t}\n\n\treturn obj\n}\n\n// propsSetAtLeastOnce is a Set that tracks which reactive properties have been\n// set at least once.\nconst propsSetAtLeastOnce = new WeakMap>()\n\n// @lume/element uses this to detect if a reactive prop has been set, and if so\n// will not overwrite the value with any pre-existing value from custom element\n// pre-upgrade.\nexport function __isPropSetAtLeastOnce(instance: object, prop: string | symbol) {\n\treturn !!propsSetAtLeastOnce.get(instance)?.has(prop)\n}\n\nexport function __trackPropSetAtLeastOnce(instance: object, prop: string | symbol) {\n\tif (!propsSetAtLeastOnce.has(instance)) propsSetAtLeastOnce.set(instance, new Set())\n\tpropsSetAtLeastOnce.get(instance)!.add(prop)\n}\n\nconst isSignalGetter = new WeakSet()\n\nexport function __createSignalAccessor(\n\tobj: T,\n\tprop: Exclude,\n\tinitialVal: unknown,\n): void {\n\tlet descriptor: PropertyDescriptor | undefined = getInheritedDescriptor(obj, prop)\n\n\tlet originalGet: (() => any) | undefined\n\tlet originalSet: ((v: any) => void) | undefined\n\tconst isAccessor = !!(descriptor?.get || descriptor?.set)\n\n\tif (descriptor) {\n\t\toriginalGet = descriptor.get\n\t\toriginalSet = descriptor.set\n\n\t\tif (originalGet && isSignalGetter.has(originalGet)) return\n\t\t// reactivity requires both\n\t\tif (isAccessor && !(originalGet && originalSet)) return warnNotReadWrite(prop)\n\n\t\tif (!isAccessor) {\n\t\t\t// no need to make a signal that can't be written to\n\t\t\tif (!descriptor.writable) return warnNotWritable(prop)\n\n\t\t\t// If there was a value descriptor, trust it as the source of truth\n\t\t\t// for initialVal. For example, if the user class modifies the value\n\t\t\t// after the initializer, it will have a different value than what\n\t\t\t// we tracked from the initializer.\n\t\t\tinitialVal = descriptor.value\n\t\t}\n\t}\n\n\tconst signalStorage = new WeakMap>()\n\n\tconst newDescriptor = {\n\t\tconfigurable: true,\n\t\tenumerable: descriptor?.enumerable,\n\t\tget: isAccessor\n\t\t\t? function (this: object): unknown {\n\t\t\t\t\t__getSignal(this, signalStorage, initialVal)()\n\t\t\t\t\treturn originalGet!.call(this)\n\t\t\t }\n\t\t\t: function (this: object): unknown {\n\t\t\t\t\treturn __getSignal(this, signalStorage, initialVal)()\n\t\t\t },\n\t\tset: isAccessor\n\t\t\t? function (this: object, newValue: unknown) {\n\t\t\t\t\toriginalSet!.call(this, newValue)\n\t\t\t\t\t__trackPropSetAtLeastOnce(this, prop)\n\n\t\t\t\t\tconst s = __getSignal(this, signalStorage, initialVal)\n\t\t\t\t\ts(typeof newValue === 'function' ? () => newValue : newValue)\n\t\t\t }\n\t\t\t: function (this: object, newValue: unknown) {\n\t\t\t\t\t__trackPropSetAtLeastOnce(this, prop)\n\n\t\t\t\t\tconst s = __getSignal(this, signalStorage, initialVal)\n\t\t\t\t\ts(typeof newValue === 'function' ? () => newValue : newValue)\n\t\t\t },\n\t}\n\n\tisSignalGetter.add(newDescriptor.get!)\n\n\tObject.defineProperty(obj, prop, newDescriptor)\n}\n\nexport function __getSignal(obj: object, storage: WeakMap>, initialVal: unknown) {\n\tlet s = storage.get(obj)\n\tif (!s) storage.set(obj, (s = createSignalFunction(initialVal, {equals: false})))\n\treturn s\n}\n\nfunction warnNotReadWrite(prop: PropertyKey) {\n\tconsole.warn(\n\t\t`Cannot signalify property named \"${String(\n\t\t\tprop,\n\t\t)}\" which had a getter or a setter, but not both. Reactivity on accessors works only when accessors have both get and set. Skipped.`,\n\t)\n}\n\nfunction warnNotWritable(prop: PropertyKey) {\n\tconsole.warn(\n\t\t`The \\`@signal\\` decorator was used on a property named \"${String(\n\t\t\tprop,\n\t\t)}\" that is not writable. Reactivity is not enabled for non-writable properties.`,\n\t)\n}\n"],"mappings":"AAAA,SAAQA,sBAAsB,QAAO,yCAAyC;AAC9E,SAAQC,MAAM,EAAEC,OAAO,QAAO,UAAU;AAExC,SAAQC,oBAAoB,QAA4B,2BAA2B;;AAInF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,OAAO,SAASC,SAASA,CAACC,GAAc,EAAE,GAAGC,KAAkE,EAAE;EAChH;EACA;EACA;EACA,MAAMC,KAAK,GAAGF,GAAG,CAACJ,MAAM,CAAM;EAC9B,IAAIM,KAAK,EAAE,OAAOF,GAAG;EAErB,MAAMG,MAAM,GAAGF,KAAK,CAACG,MAAM,GAAGH,KAAK,GAAII,MAAM,CAACC,IAAI,CAACN,GAAG,CAAC,CAAeO,MAAM,CAACF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,CAAC,OAAOD,QAAQ,KAAK,UAAU,GAAG,MAAMA,QAAQ,GAAGA,QAAQ,CAAC;IAC7D,CAAC,GACD,UAAwBA,QAAiB,EAAE;MAC3CrB,yBAAyB,CAAC,IAAI,EAAEb,IAAI,CAAC;MAErC,MAAMmC,CAAC,GAAGH,WAAW,CAAC,IAAI,EAAEJ,aAAa,EAAET,UAAU,CAAC;MACtDgB,CAAC,CAAC,OAAOD,QAAQ,KAAK,UAAU,GAAG,MAAMA,QAAQ,GAAGA,QAAQ,CAAC;IAC7D;EACJ,CAAC;EAEDjB,cAAc,CAACD,GAAG,CAACa,aAAa,CAAClB,GAAI,CAAC;EAEtCf,MAAM,CAACwC,cAAc,CAAC7C,GAAG,EAAES,IAAI,EAAE6B,aAAa,CAAC;AAChD;AAEA,OAAO,SAASG,WAAWA,CAACzC,GAAW,EAAE8C,OAAiD,EAAElB,UAAmB,EAAE;EAChH,IAAIgB,CAAC,GAAGE,OAAO,CAAC1B,GAAG,CAACpB,GAAG,CAAC;EACxB,IAAI,CAAC4C,CAAC,EAAEE,OAAO,CAACvB,GAAG,CAACvB,GAAG,EAAG4C,CAAC,GAAG9C,oBAAoB,CAAC8B,UAAU,EAAE;IAACmB,MAAM,EAAE;EAAK,CAAC,CAAE,CAAC;EACjF,OAAOH,CAAC;AACT;AAEA,SAASX,gBAAgBA,CAACxB,IAAiB,EAAE;EAC5CuC,OAAO,CAACC,IAAI,CACX,oCAAoCC,MAAM,CACzCzC,IACD,CAAC,mIACF,CAAC;AACF;AAEA,SAAS0B,eAAeA,CAAC1B,IAAiB,EAAE;EAC3CuC,OAAO,CAACC,IAAI,CACX,2DAA2DC,MAAM,CAChEzC,IACD,CAAC,gFACF,CAAC;AACF","ignoreList":[]} \ No newline at end of file +{"version":3,"file":"signalify.js","names":["getInheritedDescriptor","$PROXY","untrack","createSignalFunction","signalify","obj","props","proxy","_props","length","Object","keys","concat","getOwnPropertySymbols","prop","isTuple","Array","isArray","_prop","initialValue","__createSignalAccessor","propsSetAtLeastOnce","WeakMap","__isPropSetAtLeastOnce","instance","get","has","__trackPropSetAtLeastOnce","set","Set","add","isSignalGetter","WeakSet","initialVal","descriptor","originalGet","originalSet","isAccessor","warnNotReadWrite","writable","warnNotWritable","value","signalStorage","newDescriptor","configurable","enumerable","__getSignal","call","newValue","s","defineProperty","storage","equals","console","warn","String"],"sources":["../../src/signals/signalify.ts"],"sourcesContent":["import {getInheritedDescriptor} from 'lowclass/dist/getInheritedDescriptor.js'\nimport {$PROXY, untrack} from 'solid-js'\nimport type {PropKey} from '../decorators/types.js'\nimport {createSignalFunction, type SignalFunction} from './createSignalFunction.js'\n\ntype AnyObject = Record\n\n/**\n * Convert properties on an object into Solid signal-backed properties.\n *\n * There are two ways to use this: either by defining which properties to\n * convert to signal-backed properties by providing an array as property names\n * in the second arg, which is useful on plain objects, or by passing in `this`\n * and `this.constructor` within the `constructor` of a class that has\n * properties decorated with `@signal`.\n *\n * Example with a class:\n *\n * ```js\n * import {signalify} from 'classy-solid'\n * import {createEffect} from 'solid-js'\n *\n * class Counter {\n * count = 0\n *\n * constructor() {\n * signalify(this, 'count')\n * setInterval(() => this.count++, 1000)\n * }\n * }\n *\n * const counter = new Counter\n *\n * createEffect(() => {\n * console.log('count:', counter.count)\n * })\n * ```\n *\n * Example with a plain object:\n *\n * ```js\n * import {signalify} from 'classy-solid'\n * import {createEffect} from 'solid-js'\n *\n * const counter = {\n * count: 0\n * }\n *\n * signalify(counter, 'count')\n * setInterval(() => counter.count++, 1000)\n *\n * createEffect(() => {\n * console.log('count:', counter.count)\n * })\n * ```\n */\nexport function signalify(obj: T): T\nexport function signalify(obj: T, ...props: (keyof T)[]): T\nexport function signalify(obj: T, ...props: [key: keyof T, initialValue: unknown][]): T\nexport function signalify(obj: AnyObject, ...props: [key: PropertyKey, initialValue: unknown][] | PropertyKey[]) {\n\t// Special case for Solid proxies: if the object is already a solid proxy,\n\t// all properties are already reactive, no need to signalify.\n\t// @ts-expect-error special indexed access\n\tconst proxy = obj[$PROXY] as T\n\tif (proxy) return obj\n\n\tconst _props = props.length ? props : (Object.keys(obj) as PropKey[]).concat(Object.getOwnPropertySymbols(obj))\n\n\t// Use `untrack` here to be extra safe the initial value doesn't count as a\n\t// dependency and cause a reactivity loop.\n\tfor (const prop of _props) {\n\t\tconst isTuple = Array.isArray(prop)\n\t\t// We cast from PropertyKey to PropKey because keys can't actually be number, only string | symbol.\n\t\tconst _prop = (isTuple ? prop[0] : prop) as PropKey\n\t\tconst initialValue = isTuple ? prop[1] : untrack(() => obj[_prop])\n\n\t\t__createSignalAccessor(obj, _prop, initialValue)\n\t}\n\n\treturn obj\n}\n\n// propsSetAtLeastOnce is a Set that tracks which reactive properties have been\n// set at least once.\nconst propsSetAtLeastOnce = new WeakMap>()\n\n// @lume/element uses this to detect if a reactive prop has been set, and if so\n// will not overwrite the value with any pre-existing value from custom element\n// pre-upgrade.\nexport function __isPropSetAtLeastOnce(instance: object, prop: string | symbol) {\n\treturn !!propsSetAtLeastOnce.get(instance)?.has(prop)\n}\n\nexport function __trackPropSetAtLeastOnce(instance: object, prop: string | symbol) {\n\tif (!propsSetAtLeastOnce.has(instance)) propsSetAtLeastOnce.set(instance, new Set())\n\tpropsSetAtLeastOnce.get(instance)!.add(prop)\n}\n\nexport const isSignalGetter = new WeakSet()\n\nexport function __createSignalAccessor(\n\tobj: T,\n\tprop: Exclude,\n\tinitialVal: unknown,\n): void {\n\tlet descriptor: PropertyDescriptor | undefined = getInheritedDescriptor(obj, prop)\n\n\tlet originalGet: (() => any) | undefined\n\tlet originalSet: ((v: any) => void) | undefined\n\tconst isAccessor = !!(descriptor?.get || descriptor?.set)\n\n\tif (descriptor) {\n\t\toriginalGet = descriptor.get\n\t\toriginalSet = descriptor.set\n\n\t\tif (originalGet && isSignalGetter.has(originalGet)) return\n\t\t// reactivity requires both\n\t\tif (isAccessor && !(originalGet && originalSet)) return warnNotReadWrite(prop)\n\n\t\tif (!isAccessor) {\n\t\t\t// no need to make a signal that can't be written to\n\t\t\tif (!descriptor.writable) return warnNotWritable(prop)\n\n\t\t\t// If there was a value descriptor, trust it as the source of truth\n\t\t\t// for initialVal. For example, if the user class modifies the value\n\t\t\t// after the initializer, it will have a different value than what\n\t\t\t// we tracked from the initializer.\n\t\t\tinitialVal = descriptor.value\n\t\t}\n\t}\n\n\tconst signalStorage = new WeakMap>()\n\n\tconst newDescriptor = {\n\t\tconfigurable: true,\n\t\tenumerable: descriptor?.enumerable,\n\t\tget: isAccessor\n\t\t\t? function (this: object): unknown {\n\t\t\t\t\t__getSignal(this, signalStorage, initialVal)()\n\t\t\t\t\treturn originalGet!.call(this)\n\t\t\t }\n\t\t\t: function (this: object): unknown {\n\t\t\t\t\treturn __getSignal(this, signalStorage, initialVal)()\n\t\t\t },\n\t\tset: isAccessor\n\t\t\t? function (this: object, newValue: unknown) {\n\t\t\t\t\toriginalSet!.call(this, newValue)\n\t\t\t\t\t__trackPropSetAtLeastOnce(this, prop)\n\n\t\t\t\t\tconst s = __getSignal(this, signalStorage, initialVal)\n\t\t\t\t\ts(typeof newValue === 'function' ? () => newValue : newValue)\n\t\t\t }\n\t\t\t: function (this: object, newValue: unknown) {\n\t\t\t\t\t__trackPropSetAtLeastOnce(this, prop)\n\n\t\t\t\t\tconst s = __getSignal(this, signalStorage, initialVal)\n\t\t\t\t\ts(typeof newValue === 'function' ? () => newValue : newValue)\n\t\t\t },\n\t}\n\n\tisSignalGetter.add(newDescriptor.get!)\n\n\tObject.defineProperty(obj, prop, newDescriptor)\n}\n\nexport function __getSignal(obj: object, storage: WeakMap>, initialVal: unknown) {\n\tlet s = storage.get(obj)\n\tif (!s) storage.set(obj, (s = createSignalFunction(initialVal, {equals: false})))\n\treturn s\n}\n\nfunction warnNotReadWrite(prop: PropertyKey) {\n\tconsole.warn(\n\t\t`Cannot signalify property named \"${String(\n\t\t\tprop,\n\t\t)}\" which had a getter or a setter, but not both. Reactivity on accessors works only when accessors have both get and set. Skipped.`,\n\t)\n}\n\nfunction warnNotWritable(prop: PropertyKey) {\n\tconsole.warn(\n\t\t`The \\`@signal\\` decorator was used on a property named \"${String(\n\t\t\tprop,\n\t\t)}\" that is not writable. Reactivity is not enabled for non-writable properties.`,\n\t)\n}\n"],"mappings":"AAAA,SAAQA,sBAAsB,QAAO,yCAAyC;AAC9E,SAAQC,MAAM,EAAEC,OAAO,QAAO,UAAU;AAExC,SAAQC,oBAAoB,QAA4B,2BAA2B;;AAInF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,OAAO,SAASC,SAASA,CAACC,GAAc,EAAE,GAAGC,KAAkE,EAAE;EAChH;EACA;EACA;EACA,MAAMC,KAAK,GAAGF,GAAG,CAACJ,MAAM,CAAM;EAC9B,IAAIM,KAAK,EAAE,OAAOF,GAAG;EAErB,MAAMG,MAAM,GAAGF,KAAK,CAACG,MAAM,GAAGH,KAAK,GAAII,MAAM,CAACC,IAAI,CAACN,GAAG,CAAC,CAAeO,MAAM,CAACF,MAAM,CAACG,qBAAqB,CAACR,GAAG,CAAC,CAAC;;EAE/G;EACA;EACA,KAAK,MAAMS,IAAI,IAAIN,MAAM,EAAE;IAC1B,MAAMO,OAAO,GAAGC,KAAK,CAACC,OAAO,CAACH,IAAI,CAAC;IACnC;IACA,MAAMI,KAAK,GAAIH,OAAO,GAAGD,IAAI,CAAC,CAAC,CAAC,GAAGA,IAAgB;IACnD,MAAMK,YAAY,GAAGJ,OAAO,GAAGD,IAAI,CAAC,CAAC,CAAC,GAAGZ,OAAO,CAAC,MAAMG,GAAG,CAACa,KAAK,CAAC,CAAC;IAElEE,sBAAsB,CAACf,GAAG,EAAEa,KAAK,EAAEC,YAAY,CAAC;EAC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AAc,CAAC7C,GAAG,EAAES,IAAI,EAAE6B,aAAa,CAAC;AAChD;AAEA,OAAO,SAASG,WAAWA,CAACzC,GAAW,EAAE8C,OAAiD,EAAElB,UAAmB,EAAE;EAChH,IAAIgB,CAAC,GAAGE,OAAO,CAAC1B,GAAG,CAACpB,GAAG,CAAC;EACxB,IAAI,CAAC4C,CAAC,EAAEE,OAAO,CAACvB,GAAG,CAACvB,GAAG,EAAG4C,CAAC,GAAG9C,oBAAoB,CAAC8B,UAAU,EAAE;IAACmB,MAAM,EAAE;EAAK,CAAC,CAAE,CAAC;EACjF,OAAOH,CAAC;AACT;AAEA,SAASX,gBAAgBA,CAACxB,IAAiB,EAAE;EAC5CuC,OAAO,CAACC,IAAI,CACX,oCAAoCC,MAAM,CACzCzC,IACD,CAAC,mIACF,CAAC;AACF;AAEA,SAAS0B,eAAeA,CAAC1B,IAAiB,EAAE;EAC3CuC,OAAO,CAACC,IAAI,CACX,2DAA2DC,MAAM,CAChEzC,IACD,CAAC,gFACF,CAAC;AACF","ignoreList":[]} \ No newline at end of file diff --git a/dist/signals/signalify.test.js b/dist/signals/signalify.test.js index c80adbd..6ddb4cc 100644 --- a/dist/signals/signalify.test.js +++ b/dist/signals/signalify.test.js @@ -53,7 +53,7 @@ describe('classy-solid', () => { // A deeper effect will be reading the property. createEffect(() => { - console.log(obj.n); + obj.n; }); }); diff --git a/dist/signals/signalify.test.js.map b/dist/signals/signalify.test.js.map index 86e4549..ca8434a 100644 --- a/dist/signals/signalify.test.js.map +++ b/dist/signals/signalify.test.js.map @@ -1 +1 @@ -{"version":3,"file":"signalify.test.js","names":["createMutable","signalify","testButterflyProps","createEffect","untrack","describe","it","obj","n","obj2","expect","toBe","butterfly","colors","_wingSize","wingSize","s","b","test","signalifyInitially","console","log","Butterfly","constructor","b2","prototype","Foo","amount","Bar","double","count","a","foo","name","Object","assign","create","countA","countB"],"sources":["../../src/signals/signalify.test.ts"],"sourcesContent":["import {createMutable} from 'solid-js/store'\nimport {signalify} from './signalify.js'\nimport {testButterflyProps} from '../index.test.js'\nimport {createEffect, untrack} from 'solid-js'\n\ndescribe('classy-solid', () => {\n\tdescribe('signalify()', () => {\n\t\tit('returns the same object that was passed in', () => {\n\t\t\tlet obj = {n: 123}\n\t\t\tlet obj2 = signalify(obj, 'n')\n\t\t\texpect(obj).toBe(obj2)\n\n\t\t\tobj = createMutable({n: 123})\n\t\t\tobj2 = signalify(obj, 'n')\n\t\t\texpect(obj).toBe(obj2)\n\t\t})\n\n\t\tdescribe('making objects reactive with signalify()', () => {\n\t\t\tit('', () => {\n\t\t\t\tconst butterfly = {\n\t\t\t\t\tcolors: 3,\n\n\t\t\t\t\t_wingSize: 2,\n\n\t\t\t\t\tget wingSize() {\n\t\t\t\t\t\treturn this._wingSize\n\t\t\t\t\t},\n\t\t\t\t\tset wingSize(s: number) {\n\t\t\t\t\t\tthis._wingSize = s\n\t\t\t\t\t},\n\t\t\t\t}\n\n\t\t\t\tconst b = signalify(butterfly, 'colors', 'wingSize')\n\n\t\t\t\ttestButterflyProps(b)\n\n\t\t\t\t// quick type check:\n\t\t\t\t// @ts-expect-error \"foo\" is not a property on butterfly\n\t\t\t\tsignalify(butterfly, 'colors', 'wingSize', 'foo')\n\t\t\t})\n\n\t\t\tit('is not tracked inside of an effect to prevent loops', () => {\n\t\t\t\ttest(true)\n\t\t\t\ttest(false)\n\n\t\t\t\tfunction test(signalifyInitially: boolean) {\n\t\t\t\t\t// Library author provides obj\n\t\t\t\t\tconst obj = {n: 123}\n\t\t\t\t\tif (signalifyInitially) signalify(obj, 'n') // library author might signalify obj.n\n\n\t\t\t\t\t// User code:\n\t\t\t\t\tcreateEffect(() => {\n\t\t\t\t\t\t// o.n may or may not already be signalified, user does not know, but they want to be sure they can react to its changes.\n\t\t\t\t\t\tsignalify(obj, 'n')\n\n\t\t\t\t\t\tobj.n = 123 // does not make an infinite loop\n\n\t\t\t\t\t\t// A deeper effect will be reading the property.\n\t\t\t\t\t\tcreateEffect(() => {\n\t\t\t\t\t\t\tconsole.log(obj.n)\n\t\t\t\t\t\t})\n\t\t\t\t\t})\n\n\t\t\t\t\t// No expectations in this test, the test passes if a maximum\n\t\t\t\t\t// callstack size error (infinite loop) does not happen.\n\t\t\t\t}\n\t\t\t})\n\t\t})\n\n\t\tdescribe('making reactive classes with signalify instead of with decorators', () => {\n\t\t\tit('makes class fields reactive, not using any decorators', () => {\n\t\t\t\tclass Butterfly {\n\t\t\t\t\tcolors = 3\n\n\t\t\t\t\t#wingSize = 2\n\n\t\t\t\t\tget wingSize() {\n\t\t\t\t\t\treturn this.#wingSize\n\t\t\t\t\t}\n\t\t\t\t\tset wingSize(s: number) {\n\t\t\t\t\t\tthis.#wingSize = s\n\t\t\t\t\t}\n\n\t\t\t\t\tconstructor() {\n\t\t\t\t\t\tsignalify(this, 'colors', 'wingSize')\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst b = new Butterfly()\n\n\t\t\t\ttestButterflyProps(b)\n\n\t\t\t\t// quick type check:\n\t\t\t\tconst b2 = new Butterfly()\n\t\t\t\t// @ts-expect-error \"foo\" is not a property on Butterfly\n\t\t\t\tsignalify(b2, 'colors', 'wingSize', 'foo')\n\t\t\t})\n\n\t\t\tit('makes constructor properties reactive, not using any decorators', () => {\n\t\t\t\tclass Butterfly {\n\t\t\t\t\tdeclare colors: number\n\n\t\t\t\t\t#wingSize: number\n\n\t\t\t\t\tget wingSize() {\n\t\t\t\t\t\treturn this.#wingSize\n\t\t\t\t\t}\n\t\t\t\t\tset wingSize(s: number) {\n\t\t\t\t\t\tthis.#wingSize = s\n\t\t\t\t\t}\n\n\t\t\t\t\tconstructor() {\n\t\t\t\t\t\tthis.colors = 3\n\t\t\t\t\t\tthis.#wingSize = 2\n\n\t\t\t\t\t\tsignalify(this, 'colors', 'wingSize')\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst b = new Butterfly()\n\n\t\t\t\ttestButterflyProps(b)\n\t\t\t})\n\n\t\t\tit('works with a function-style class, with signalify in the constructor', () => {\n\t\t\t\tfunction Butterfly() {\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tthis.colors = 3\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tthis._wingSize = 2\n\n\t\t\t\t\t// @ts-ignore no type checking for ES5-style classes.\n\t\t\t\t\tsignalify(this, 'colors', 'wingSize')\n\t\t\t\t}\n\n\t\t\t\tButterfly.prototype = {\n\t\t\t\t\tget wingSize() {\n\t\t\t\t\t\treturn this._wingSize\n\t\t\t\t\t},\n\t\t\t\t\tset wingSize(s: number) {\n\t\t\t\t\t\tthis._wingSize = s\n\t\t\t\t\t},\n\t\t\t\t}\n\n\t\t\t\t// @ts-ignore\n\t\t\t\tconst b = new Butterfly()\n\t\t\t\ttestButterflyProps(b)\n\t\t\t})\n\n\t\t\tit('works with a function-style class, with properties on the prototype, and signalify in constructor', () => {\n\t\t\t\tfunction Butterfly() {\n\t\t\t\t\t// @ts-ignore no type checking for ES5-style classes.\n\t\t\t\t\tsignalify(this, 'colors', 'wingSize')\n\t\t\t\t}\n\n\t\t\t\tButterfly.prototype = {\n\t\t\t\t\tcolors: 3,\n\t\t\t\t\t_wingSize: 2,\n\n\t\t\t\t\tget wingSize() {\n\t\t\t\t\t\treturn this._wingSize\n\t\t\t\t\t},\n\t\t\t\t\tset wingSize(s: number) {\n\t\t\t\t\t\tthis._wingSize = s\n\t\t\t\t\t},\n\t\t\t\t}\n\n\t\t\t\t// @ts-ignore no type checking for ES5-style classes.\n\t\t\t\tconst b = new Butterfly()\n\t\t\t\ttestButterflyProps(b)\n\t\t\t})\n\n\t\t\tit('can be used on a function-style class, with properties on the prototype, and signalify on the prototype', () => {\n\t\t\t\tfunction Butterfly() {}\n\n\t\t\t\tButterfly.prototype = {\n\t\t\t\t\tcolors: 3,\n\t\t\t\t\t_wingSize: 2,\n\n\t\t\t\t\tget wingSize() {\n\t\t\t\t\t\treturn this._wingSize\n\t\t\t\t\t},\n\t\t\t\t\tset wingSize(s: number) {\n\t\t\t\t\t\tthis._wingSize = s\n\t\t\t\t\t},\n\t\t\t\t}\n\n\t\t\t\tsignalify(Butterfly.prototype, 'colors', 'wingSize')\n\n\t\t\t\t// @ts-ignore no type checking for ES5-style classes.\n\t\t\t\tconst b = new Butterfly()\n\t\t\t\ttestButterflyProps(b)\n\t\t\t})\n\n\t\t\tit('can be used on a function-style class, with properties in the constructor, and signalify on the prototype', () => {\n\t\t\t\tfunction Butterfly() {\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tthis.colors = 3\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tthis._wingSize = 2\n\t\t\t\t}\n\n\t\t\t\tButterfly.prototype = {\n\t\t\t\t\tget wingSize() {\n\t\t\t\t\t\treturn this._wingSize\n\t\t\t\t\t},\n\t\t\t\t\tset wingSize(s: number) {\n\t\t\t\t\t\tthis._wingSize = s\n\t\t\t\t\t},\n\t\t\t\t}\n\n\t\t\t\tsignalify(Butterfly.prototype, 'colors', 'wingSize')\n\n\t\t\t\t// @ts-ignore\n\t\t\t\tconst b = new Butterfly()\n\t\t\t\ttestButterflyProps(b)\n\t\t\t})\n\n\t\t\tit('show that signalify causes constructor to be reactive when used manually instead of decorators', () => {\n\t\t\t\tclass Foo {\n\t\t\t\t\tamount = 3\n\n\t\t\t\t\tconstructor() {\n\t\t\t\t\t\tsignalify(this, 'amount')\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tclass Bar extends Foo {\n\t\t\t\t\tdouble = 0\n\n\t\t\t\t\tconstructor() {\n\t\t\t\t\t\tsuper()\n\t\t\t\t\t\tsignalify(this, 'double')\n\t\t\t\t\t\tthis.double = this.amount * 2 // this tracks access of .amount\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tlet count = 0\n\t\t\t\tlet b!: Bar\n\n\t\t\t\tcreateEffect(() => {\n\t\t\t\t\tb = new Bar() // tracks .amount\n\t\t\t\t\tcount++\n\t\t\t\t})\n\n\t\t\t\texpect(count).toBe(1)\n\n\t\t\t\tb.amount = 4 // triggers\n\n\t\t\t\texpect(count).toBe(2)\n\t\t\t})\n\n\t\t\tit('show how to manually untrack constructors when not using decorators', () => {\n\t\t\t\tclass Foo {\n\t\t\t\t\tamount = 3\n\n\t\t\t\t\tconstructor() {\n\t\t\t\t\t\tsignalify(this, 'amount')\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tclass Bar extends Foo {\n\t\t\t\t\tdouble = 0\n\n\t\t\t\t\tconstructor() {\n\t\t\t\t\t\tsuper()\n\t\t\t\t\t\tsignalify(this, 'double')\n\n\t\t\t\t\t\tuntrack(() => {\n\t\t\t\t\t\t\tthis.double = this.amount * 2\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tlet count = 0\n\t\t\t\tlet b!: Bar\n\n\t\t\t\tcreateEffect(() => {\n\t\t\t\t\tb = new Bar() // does not track .amount\n\t\t\t\t\tcount++\n\t\t\t\t})\n\n\t\t\t\texpect(count).toBe(1)\n\n\t\t\t\tb.amount = 4 // will not trigger\n\n\t\t\t\texpect(count).toBe(1)\n\t\t\t})\n\t\t})\n\n\t\tit('creates signal storage per descriptor+object pair, not per descriptor', () => {\n\t\t\t// This ensures we don't accidentally share a signal with multiple\n\t\t\t// objects. For example, we don't want a single signal per descriptor\n\t\t\t// because if the descriptor is on a prototype object, then that single\n\t\t\t// signal will erroneously be used by all objects extending from that\n\t\t\t// prototype.\n\n\t\t\tconst a = signalify({foo: 0, name: 'a'}, 'foo')\n\t\t\tconst b = Object.assign(Object.create(a) as typeof a, {name: 'b'})\n\n\t\t\texpect(a.foo).toBe(0)\n\t\t\texpect(b.foo).toBe(0)\n\n\t\t\tlet countA = 0\n\n\t\t\tcreateEffect(() => {\n\t\t\t\ta.foo\n\t\t\t\tcountA++\n\t\t\t})\n\n\t\t\tlet countB = 0\n\n\t\t\tcreateEffect(() => {\n\t\t\t\tb.foo\n\t\t\t\tcountB++\n\t\t\t})\n\n\t\t\texpect(countA).toBe(1)\n\t\t\texpect(countB).toBe(1)\n\n\t\t\ta.foo++\n\n\t\t\texpect(a.foo).toBe(1)\n\t\t\texpect(countA).toBe(2)\n\n\t\t\t// ensure that updating a's foo property did not update b's foo\n\t\t\t// property or trigger b's effect, despite that the property is\n\t\t\t// defined in a single location on the prototype.\n\t\t\t// @ts-ignore\n\t\t\texpect(b.foo).toBe(0)\n\t\t\texpect(countB).toBe(1)\n\t\t})\n\t})\n})\n"],"mappings":"AAAA,SAAQA,aAAa,QAAO,gBAAgB;AAC5C,SAAQC,SAAS,QAAO,gBAAgB;AACxC,SAAQC,kBAAkB,QAAO,kBAAkB;AACnD,SAAQC,YAAY,EAAEC,OAAO,QAAO,UAAU;AAE9CC,QAAQ,CAAC,cAAc,EAAE,MAAM;EAC9BA,QAAQ,CAAC,aAAa,EAAE,MAAM;IAC7BC,EAAE,CAAC,4CAA4C,EAAE,MAAM;MACtD,IAAIC,GAAG,GAAG;QAACC,CAAC,EAAE;MAAG,CAAC;MAClB,IAAIC,IAAI,GAAGR,SAAS,CAACM,GAAG,EAAE,GAAG,CAAC;MAC9BG,MAAM,CAACH,GAAG,CAAC,CAACI,IAAI,CAACF,IAAI,CAAC;MAEtBF,GAAG,GAAGP,aAAa,CAAC;QAACQ,CAAC,EAAE;MAAG,CAAC,CAAC;MAC7BC,IAAI,GAAGR,SAAS,CAACM,GAAG,EAAE,GAAG,CAAC;MAC1BG,MAAM,CAACH,GAAG,CAAC,CAACI,IAAI,CAACF,IAAI,CAAC;IACvB,CAAC,CAAC;IAEFJ,QAAQ,CAAC,0CAA0C,EAAE,MAAM;MAC1DC,EAAE,CAAC,EAAE,EAAE,MAAM;QACZ,MAAMM,SAAS,GAAG;UACjBC,MAAM,EAAE,CAAC;UAETC,SAAS,EAAE,CAAC;UAEZ,IAAIC,QAAQA,CAAA,EAAG;YACd,OAAO,IAAI,CAACD,SAAS;UACtB,CAAC;UACD,IAAIC,QAAQA,CAACC,CAAS,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MAAM,GAAG,CAAC;MAEdlC,YAAY,CAAC,MAAM;QAClB4B,CAAC,CAACC,GAAG;QACLK,MAAM,EAAE;MACT,CAAC,CAAC;MAEF,IAAIC,MAAM,GAAG,CAAC;MAEdnC,YAAY,CAAC,MAAM;QAClBc,CAAC,CAACe,GAAG;QACLM,MAAM,EAAE;MACT,CAAC,CAAC;MAEF5B,MAAM,CAAC2B,MAAM,CAAC,CAAC1B,IAAI,CAAC,CAAC,CAAC;MACtBD,MAAM,CAAC4B,MAAM,CAAC,CAAC3B,IAAI,CAAC,CAAC,CAAC;MAEtBoB,CAAC,CAACC,GAAG,EAAE;MAEPtB,MAAM,CAACqB,CAAC,CAACC,GAAG,CAAC,CAACrB,IAAI,CAAC,CAAC,CAAC;MACrBD,MAAM,CAAC2B,MAAM,CAAC,CAAC1B,IAAI,CAAC,CAAC,CAAC;;MAEtB;MACA;MACA;MACA;MACAD,MAAM,CAACO,CAAC,CAACe,GAAG,CAAC,CAACrB,IAAI,CAAC,CAAC,CAAC;MACrBD,MAAM,CAAC4B,MAAM,CAAC,CAAC3B,IAAI,CAAC,CAAC,CAAC;IACvB,CAAC,CAAC;EACH,CAAC,CAAC;AACH,CAAC,CAAC","ignoreList":[]} \ No newline at end of file +{"version":3,"file":"signalify.test.js","names":["createMutable","signalify","testButterflyProps","createEffect","untrack","describe","it","obj","n","obj2","expect","toBe","butterfly","colors","_wingSize","wingSize","s","b","test","signalifyInitially","Butterfly","constructor","b2","prototype","Foo","amount","Bar","double","count","a","foo","name","Object","assign","create","countA","countB"],"sources":["../../src/signals/signalify.test.ts"],"sourcesContent":["import {createMutable} from 'solid-js/store'\nimport {signalify} from './signalify.js'\nimport {testButterflyProps} from '../index.test.js'\nimport {createEffect, untrack} from 'solid-js'\n\ndescribe('classy-solid', () => {\n\tdescribe('signalify()', () => {\n\t\tit('returns the same object that was passed in', () => {\n\t\t\tlet obj = {n: 123}\n\t\t\tlet obj2 = signalify(obj, 'n')\n\t\t\texpect(obj).toBe(obj2)\n\n\t\t\tobj = createMutable({n: 123})\n\t\t\tobj2 = signalify(obj, 'n')\n\t\t\texpect(obj).toBe(obj2)\n\t\t})\n\n\t\tdescribe('making objects reactive with signalify()', () => {\n\t\t\tit('', () => {\n\t\t\t\tconst butterfly = {\n\t\t\t\t\tcolors: 3,\n\n\t\t\t\t\t_wingSize: 2,\n\n\t\t\t\t\tget wingSize() {\n\t\t\t\t\t\treturn this._wingSize\n\t\t\t\t\t},\n\t\t\t\t\tset wingSize(s: number) {\n\t\t\t\t\t\tthis._wingSize = s\n\t\t\t\t\t},\n\t\t\t\t}\n\n\t\t\t\tconst b = signalify(butterfly, 'colors', 'wingSize')\n\n\t\t\t\ttestButterflyProps(b)\n\n\t\t\t\t// quick type check:\n\t\t\t\t// @ts-expect-error \"foo\" is not a property on butterfly\n\t\t\t\tsignalify(butterfly, 'colors', 'wingSize', 'foo')\n\t\t\t})\n\n\t\t\tit('is not tracked inside of an effect to prevent loops', () => {\n\t\t\t\ttest(true)\n\t\t\t\ttest(false)\n\n\t\t\t\tfunction test(signalifyInitially: boolean) {\n\t\t\t\t\t// Library author provides obj\n\t\t\t\t\tconst obj = {n: 123}\n\t\t\t\t\tif (signalifyInitially) signalify(obj, 'n') // library author might signalify obj.n\n\n\t\t\t\t\t// User code:\n\t\t\t\t\tcreateEffect(() => {\n\t\t\t\t\t\t// o.n may or may not already be signalified, user does not know, but they want to be sure they can react to its changes.\n\t\t\t\t\t\tsignalify(obj, 'n')\n\n\t\t\t\t\t\tobj.n = 123 // does not make an infinite loop\n\n\t\t\t\t\t\t// A deeper effect will be reading the property.\n\t\t\t\t\t\tcreateEffect(() => {\n\t\t\t\t\t\t\tobj.n\n\t\t\t\t\t\t})\n\t\t\t\t\t})\n\n\t\t\t\t\t// No expectations in this test, the test passes if a maximum\n\t\t\t\t\t// callstack size error (infinite loop) does not happen.\n\t\t\t\t}\n\t\t\t})\n\t\t})\n\n\t\tdescribe('making reactive classes with signalify instead of with decorators', () => {\n\t\t\tit('makes class fields reactive, not using any decorators', () => {\n\t\t\t\tclass Butterfly {\n\t\t\t\t\tcolors = 3\n\n\t\t\t\t\t#wingSize = 2\n\n\t\t\t\t\tget wingSize() {\n\t\t\t\t\t\treturn this.#wingSize\n\t\t\t\t\t}\n\t\t\t\t\tset wingSize(s: number) {\n\t\t\t\t\t\tthis.#wingSize = s\n\t\t\t\t\t}\n\n\t\t\t\t\tconstructor() {\n\t\t\t\t\t\tsignalify(this, 'colors', 'wingSize')\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst b = new Butterfly()\n\n\t\t\t\ttestButterflyProps(b)\n\n\t\t\t\t// quick type check:\n\t\t\t\tconst b2 = new Butterfly()\n\t\t\t\t// @ts-expect-error \"foo\" is not a property on Butterfly\n\t\t\t\tsignalify(b2, 'colors', 'wingSize', 'foo')\n\t\t\t})\n\n\t\t\tit('makes constructor properties reactive, not using any decorators', () => {\n\t\t\t\tclass Butterfly {\n\t\t\t\t\tdeclare colors: number\n\n\t\t\t\t\t#wingSize: number\n\n\t\t\t\t\tget wingSize() {\n\t\t\t\t\t\treturn this.#wingSize\n\t\t\t\t\t}\n\t\t\t\t\tset wingSize(s: number) {\n\t\t\t\t\t\tthis.#wingSize = s\n\t\t\t\t\t}\n\n\t\t\t\t\tconstructor() {\n\t\t\t\t\t\tthis.colors = 3\n\t\t\t\t\t\tthis.#wingSize = 2\n\n\t\t\t\t\t\tsignalify(this, 'colors', 'wingSize')\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst b = new Butterfly()\n\n\t\t\t\ttestButterflyProps(b)\n\t\t\t})\n\n\t\t\tit('works with a function-style class, with signalify in the constructor', () => {\n\t\t\t\tfunction Butterfly() {\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tthis.colors = 3\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tthis._wingSize = 2\n\n\t\t\t\t\t// @ts-ignore no type checking for ES5-style classes.\n\t\t\t\t\tsignalify(this, 'colors', 'wingSize')\n\t\t\t\t}\n\n\t\t\t\tButterfly.prototype = {\n\t\t\t\t\tget wingSize() {\n\t\t\t\t\t\treturn this._wingSize\n\t\t\t\t\t},\n\t\t\t\t\tset wingSize(s: number) {\n\t\t\t\t\t\tthis._wingSize = s\n\t\t\t\t\t},\n\t\t\t\t}\n\n\t\t\t\t// @ts-ignore\n\t\t\t\tconst b = new Butterfly()\n\t\t\t\ttestButterflyProps(b)\n\t\t\t})\n\n\t\t\tit('works with a function-style class, with properties on the prototype, and signalify in constructor', () => {\n\t\t\t\tfunction Butterfly() {\n\t\t\t\t\t// @ts-ignore no type checking for ES5-style classes.\n\t\t\t\t\tsignalify(this, 'colors', 'wingSize')\n\t\t\t\t}\n\n\t\t\t\tButterfly.prototype = {\n\t\t\t\t\tcolors: 3,\n\t\t\t\t\t_wingSize: 2,\n\n\t\t\t\t\tget wingSize() {\n\t\t\t\t\t\treturn this._wingSize\n\t\t\t\t\t},\n\t\t\t\t\tset wingSize(s: number) {\n\t\t\t\t\t\tthis._wingSize = s\n\t\t\t\t\t},\n\t\t\t\t}\n\n\t\t\t\t// @ts-ignore no type checking for ES5-style classes.\n\t\t\t\tconst b = new Butterfly()\n\t\t\t\ttestButterflyProps(b)\n\t\t\t})\n\n\t\t\tit('can be used on a function-style class, with properties on the prototype, and signalify on the prototype', () => {\n\t\t\t\tfunction Butterfly() {}\n\n\t\t\t\tButterfly.prototype = {\n\t\t\t\t\tcolors: 3,\n\t\t\t\t\t_wingSize: 2,\n\n\t\t\t\t\tget wingSize() {\n\t\t\t\t\t\treturn this._wingSize\n\t\t\t\t\t},\n\t\t\t\t\tset wingSize(s: number) {\n\t\t\t\t\t\tthis._wingSize = s\n\t\t\t\t\t},\n\t\t\t\t}\n\n\t\t\t\tsignalify(Butterfly.prototype, 'colors', 'wingSize')\n\n\t\t\t\t// @ts-ignore no type checking for ES5-style classes.\n\t\t\t\tconst b = new Butterfly()\n\t\t\t\ttestButterflyProps(b)\n\t\t\t})\n\n\t\t\tit('can be used on a function-style class, with properties in the constructor, and signalify on the prototype', () => {\n\t\t\t\tfunction Butterfly() {\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tthis.colors = 3\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tthis._wingSize = 2\n\t\t\t\t}\n\n\t\t\t\tButterfly.prototype = {\n\t\t\t\t\tget wingSize() {\n\t\t\t\t\t\treturn this._wingSize\n\t\t\t\t\t},\n\t\t\t\t\tset wingSize(s: number) {\n\t\t\t\t\t\tthis._wingSize = s\n\t\t\t\t\t},\n\t\t\t\t}\n\n\t\t\t\tsignalify(Butterfly.prototype, 'colors', 'wingSize')\n\n\t\t\t\t// @ts-ignore\n\t\t\t\tconst b = new Butterfly()\n\t\t\t\ttestButterflyProps(b)\n\t\t\t})\n\n\t\t\tit('show that signalify causes constructor to be reactive when used manually instead of decorators', () => {\n\t\t\t\tclass Foo {\n\t\t\t\t\tamount = 3\n\n\t\t\t\t\tconstructor() {\n\t\t\t\t\t\tsignalify(this, 'amount')\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tclass Bar extends Foo {\n\t\t\t\t\tdouble = 0\n\n\t\t\t\t\tconstructor() {\n\t\t\t\t\t\tsuper()\n\t\t\t\t\t\tsignalify(this, 'double')\n\t\t\t\t\t\tthis.double = this.amount * 2 // this tracks access of .amount\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tlet count = 0\n\t\t\t\tlet b!: Bar\n\n\t\t\t\tcreateEffect(() => {\n\t\t\t\t\tb = new Bar() // tracks .amount\n\t\t\t\t\tcount++\n\t\t\t\t})\n\n\t\t\t\texpect(count).toBe(1)\n\n\t\t\t\tb.amount = 4 // triggers\n\n\t\t\t\texpect(count).toBe(2)\n\t\t\t})\n\n\t\t\tit('show how to manually untrack constructors when not using decorators', () => {\n\t\t\t\tclass Foo {\n\t\t\t\t\tamount = 3\n\n\t\t\t\t\tconstructor() {\n\t\t\t\t\t\tsignalify(this, 'amount')\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tclass Bar extends Foo {\n\t\t\t\t\tdouble = 0\n\n\t\t\t\t\tconstructor() {\n\t\t\t\t\t\tsuper()\n\t\t\t\t\t\tsignalify(this, 'double')\n\n\t\t\t\t\t\tuntrack(() => {\n\t\t\t\t\t\t\tthis.double = this.amount * 2\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tlet count = 0\n\t\t\t\tlet b!: Bar\n\n\t\t\t\tcreateEffect(() => {\n\t\t\t\t\tb = new Bar() // does not track .amount\n\t\t\t\t\tcount++\n\t\t\t\t})\n\n\t\t\t\texpect(count).toBe(1)\n\n\t\t\t\tb.amount = 4 // will not trigger\n\n\t\t\t\texpect(count).toBe(1)\n\t\t\t})\n\t\t})\n\n\t\tit('creates signal storage per descriptor+object pair, not per descriptor', () => {\n\t\t\t// This ensures we don't accidentally share a signal with multiple\n\t\t\t// objects. For example, we don't want a single signal per descriptor\n\t\t\t// because if the descriptor is on a prototype object, then that single\n\t\t\t// signal will erroneously be used by all objects extending from that\n\t\t\t// prototype.\n\n\t\t\tconst a = signalify({foo: 0, name: 'a'}, 'foo')\n\t\t\tconst b = Object.assign(Object.create(a) as typeof a, {name: 'b'})\n\n\t\t\texpect(a.foo).toBe(0)\n\t\t\texpect(b.foo).toBe(0)\n\n\t\t\tlet countA = 0\n\n\t\t\tcreateEffect(() => {\n\t\t\t\ta.foo\n\t\t\t\tcountA++\n\t\t\t})\n\n\t\t\tlet countB = 0\n\n\t\t\tcreateEffect(() => {\n\t\t\t\tb.foo\n\t\t\t\tcountB++\n\t\t\t})\n\n\t\t\texpect(countA).toBe(1)\n\t\t\texpect(countB).toBe(1)\n\n\t\t\ta.foo++\n\n\t\t\texpect(a.foo).toBe(1)\n\t\t\texpect(countA).toBe(2)\n\n\t\t\t// ensure that updating a's foo property did not update b's foo\n\t\t\t// property or trigger b's effect, despite that the property is\n\t\t\t// defined in a single location on the prototype.\n\t\t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,IAAI,CAAC,CAAC,CAAC;MACtBD,MAAM,CAAC0B,MAAM,CAAC,CAACzB,IAAI,CAAC,CAAC,CAAC;MAEtBkB,CAAC,CAACC,GAAG,EAAE;MAEPpB,MAAM,CAACmB,CAAC,CAACC,GAAG,CAAC,CAACnB,IAAI,CAAC,CAAC,CAAC;MACrBD,MAAM,CAACyB,MAAM,CAAC,CAACxB,IAAI,CAAC,CAAC,CAAC;;MAEtB;MACA;MACA;MACA;MACAD,MAAM,CAACO,CAAC,CAACa,GAAG,CAAC,CAACnB,IAAI,CAAC,CAAC,CAAC;MACrBD,MAAM,CAAC0B,MAAM,CAAC,CAACzB,IAAI,CAAC,CAAC,CAAC;IACvB,CAAC,CAAC;EACH,CAAC,CAAC;AACH,CAAC,CAAC","ignoreList":[]} \ No newline at end of file diff --git a/src/decorators/signal.test.ts b/src/decorators/signal.test.ts index c6133f7..510163d 100644 --- a/src/decorators/signal.test.ts +++ b/src/decorators/signal.test.ts @@ -2,6 +2,7 @@ import {createEffect} from 'solid-js' import {testButterflyProps} from '../index.test.js' import {reactive} from './reactive.js' import {signal} from './signal.js' +import {signalify} from '../signals/signalify.js' describe('classy-solid', () => { describe('@reactive, @signal', () => { @@ -359,5 +360,47 @@ describe('classy-solid', () => { expect(count).toBe(1) expect(b!).toBe(b2) }) + + it.only('prevents duplicate signals for any property', () => { + @reactive + class Insect { + @signal venomous = 0 + + @signal accessor legs = 6 + + #eyes = 10 + @signal get eyes() { + return this.#eyes + } + @signal set eyes(n) { + this.#eyes = n + } + + antennas = 0 + + constructor() { + // This should not add any extra signals for properties that + // are already signalified by the @signal decorator + signalify(this, 'venomous', 'legs', 'eyes', 'antennas') + } + } + const i = new Insect() + + testNoDuplicateSignal(i, 'venomous') + testNoDuplicateSignal(i, 'legs') + testNoDuplicateSignal(i, 'eyes') + testNoDuplicateSignal(i, 'antennas') + + function testNoDuplicateSignal(o: Insect, prop: keyof Insect) { + let count = 0 + createEffect(() => { + count++ + o[prop] + }) + expect(count).toBe(1) + o[prop]++ + expect(count).toBe(2) // it would be 3 if there were an extra signal + } + }) }) }) diff --git a/src/decorators/signal.ts b/src/decorators/signal.ts index 7f46ff4..8214299 100644 --- a/src/decorators/signal.ts +++ b/src/decorators/signal.ts @@ -1,5 +1,5 @@ import {$PROXY} from 'solid-js' -import {__getSignal, __trackPropSetAtLeastOnce, __createSignalAccessor} from '../signals/signalify.js' +import {__getSignal, __trackPropSetAtLeastOnce, __createSignalAccessor, isSignalGetter} from '../signals/signalify.js' import type {PropKey, PropSpec} from './types.js' import type {SignalFunction} from '../signals/createSignalFunction.js' @@ -77,12 +77,9 @@ export function signal( let initialValue = propSpec.initialValue // @prod-prune - if (!Object.hasOwn(this, prop)) - // continue - throw new PropNotFoundError(prop) + if (!Object.hasOwn(this, prop)) throw new PropNotFoundError(prop) __createSignalAccessor(this as any, prop, initialValue) - // CONTINUE testing this way of finalizing signal fields } return } @@ -95,7 +92,7 @@ export function signal( const signalStorage = new WeakMap>() let initialValue: unknown = undefined - return { + const newValue = { init: function (this: object, initialVal: unknown) { initialValue = initialVal return initialVal @@ -112,6 +109,10 @@ export function signal( s(typeof newValue === 'function' ? () => newValue : newValue) }, } + + isSignalGetter.add(newValue.get) + + return newValue } else if (kind === 'getter' || kind === 'setter') { const getOrSet = value as Function const initialValue = Undefined @@ -134,10 +135,14 @@ export function signal( pairs[name] ??= 0 pairs[name]++ - return function (this: object): unknown { + const newGetter = function (this: object): unknown { __getSignal(this, signalStorage, initialValue)() return getOrSet.call(this) } + + isSignalGetter.add(newGetter) + + return newGetter } else { pairs[name] ??= 0 pairs[name]++ diff --git a/src/signals/signalify.test.ts b/src/signals/signalify.test.ts index f67a4dc..5043a38 100644 --- a/src/signals/signalify.test.ts +++ b/src/signals/signalify.test.ts @@ -57,7 +57,7 @@ describe('classy-solid', () => { // A deeper effect will be reading the property. createEffect(() => { - console.log(obj.n) + obj.n }) }) diff --git a/src/signals/signalify.ts b/src/signals/signalify.ts index d557f16..dc8a970 100644 --- a/src/signals/signalify.ts +++ b/src/signals/signalify.ts @@ -96,7 +96,7 @@ export function __trackPropSetAtLeastOnce(instance: object, prop: string | symbo propsSetAtLeastOnce.get(instance)!.add(prop) } -const isSignalGetter = new WeakSet() +export const isSignalGetter = new WeakSet() export function __createSignalAccessor( obj: T,