mutts 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +24 -2
  2. package/dist/chunks/_tslib-C-cuVLvZ.js +73 -0
  3. package/dist/chunks/_tslib-C-cuVLvZ.js.map +1 -0
  4. package/dist/chunks/_tslib-CMEnd0VE.esm.js +68 -0
  5. package/dist/chunks/_tslib-CMEnd0VE.esm.js.map +1 -0
  6. package/dist/chunks/{decorator-8qjFb7dw.js → decorator-D4DU97Zg.js} +70 -4
  7. package/dist/chunks/decorator-D4DU97Zg.js.map +1 -0
  8. package/dist/chunks/{decorator-AbRkXM5O.esm.js → decorator-GnHw1Az7.esm.js} +67 -5
  9. package/dist/chunks/decorator-GnHw1Az7.esm.js.map +1 -0
  10. package/dist/chunks/index-DBScoeCX.esm.js +1960 -0
  11. package/dist/chunks/index-DBScoeCX.esm.js.map +1 -0
  12. package/dist/chunks/index-DOTmXL89.js +1983 -0
  13. package/dist/chunks/index-DOTmXL89.js.map +1 -0
  14. package/dist/decorator.d.ts +57 -0
  15. package/dist/decorator.esm.js +1 -1
  16. package/dist/decorator.js +1 -1
  17. package/dist/destroyable.d.ts +42 -0
  18. package/dist/destroyable.esm.js +19 -1
  19. package/dist/destroyable.esm.js.map +1 -1
  20. package/dist/destroyable.js +19 -1
  21. package/dist/destroyable.js.map +1 -1
  22. package/dist/eventful.d.ts +10 -1
  23. package/dist/eventful.esm.js +5 -27
  24. package/dist/eventful.esm.js.map +1 -1
  25. package/dist/eventful.js +15 -37
  26. package/dist/eventful.js.map +1 -1
  27. package/dist/index.d.ts +52 -3
  28. package/dist/index.esm.js +3 -2
  29. package/dist/index.esm.js.map +1 -1
  30. package/dist/index.js +17 -3
  31. package/dist/index.js.map +1 -1
  32. package/dist/indexable.d.ts +26 -0
  33. package/dist/indexable.esm.js +6 -0
  34. package/dist/indexable.esm.js.map +1 -1
  35. package/dist/indexable.js +6 -0
  36. package/dist/indexable.js.map +1 -1
  37. package/dist/mutts.umd.js +1 -1
  38. package/dist/mutts.umd.js.map +1 -1
  39. package/dist/mutts.umd.min.js +1 -1
  40. package/dist/mutts.umd.min.js.map +1 -1
  41. package/dist/promiseChain.d.ts +10 -0
  42. package/dist/promiseChain.esm.js +6 -0
  43. package/dist/promiseChain.esm.js.map +1 -1
  44. package/dist/promiseChain.js +6 -0
  45. package/dist/promiseChain.js.map +1 -1
  46. package/dist/reactive.d.ts +255 -18
  47. package/dist/reactive.esm.js +4 -1458
  48. package/dist/reactive.esm.js.map +1 -1
  49. package/dist/reactive.js +29 -1471
  50. package/dist/reactive.js.map +1 -1
  51. package/dist/std-decorators.d.ts +35 -0
  52. package/dist/std-decorators.esm.js +36 -1
  53. package/dist/std-decorators.esm.js.map +1 -1
  54. package/dist/std-decorators.js +36 -1
  55. package/dist/std-decorators.js.map +1 -1
  56. package/docs/mixin.md +229 -0
  57. package/docs/reactive.md +7739 -882
  58. package/package.json +1 -1
  59. package/dist/chunks/decorator-8qjFb7dw.js.map +0 -1
  60. package/dist/chunks/decorator-AbRkXM5O.esm.js.map +0 -1
@@ -1,11 +1,20 @@
1
1
  'use strict';
2
2
 
3
- var decorator = require('./chunks/decorator-8qjFb7dw.js');
3
+ var decorator = require('./chunks/decorator-D4DU97Zg.js');
4
4
 
5
5
  // Integrated with `using` statement via Symbol.dispose
6
6
  const fr = new FinalizationRegistry((f) => f());
7
+ /**
8
+ * Symbol for marking destructor methods
9
+ */
7
10
  const destructor = Symbol('destructor');
11
+ /**
12
+ * Symbol for accessing allocated values in destroyable objects
13
+ */
8
14
  const allocatedValues = Symbol('allocated');
15
+ /**
16
+ * Error thrown when attempting to access a destroyed object
17
+ */
9
18
  class DestructionError extends Error {
10
19
  static throw(msg) {
11
20
  return () => {
@@ -69,6 +78,10 @@ function Destroyable(base, destructorObj) {
69
78
  _a.destructors = new WeakMap(),
70
79
  _a;
71
80
  }
81
+ /**
82
+ * Decorator that marks properties to be stored in the allocated object and passed to the destructor
83
+ * Use with accessor properties or explicit get/set pairs
84
+ */
72
85
  const allocated = decorator.decorator({
73
86
  setter(original, propertyKey) {
74
87
  return function (value) {
@@ -77,6 +90,11 @@ const allocated = decorator.decorator({
77
90
  };
78
91
  },
79
92
  });
93
+ /**
94
+ * Registers a callback to be called when an object is garbage collected
95
+ * @param cb - The callback function to execute on garbage collection
96
+ * @returns The object whose reference can be collected
97
+ */
80
98
  function callOnGC(cb) {
81
99
  let called = false;
82
100
  const forward = () => {
@@ -1 +1 @@
1
- {"version":3,"file":"destroyable.js","sources":["../src/destroyable.ts"],"sourcesContent":["import { decorator } from './decorator'\n\n// Integrated with `using` statement via Symbol.dispose\nconst fr = new FinalizationRegistry<() => void>((f) => f())\nexport const destructor = Symbol('destructor')\nexport const allocatedValues = Symbol('allocated')\nexport class DestructionError extends Error {\n\tstatic throw<_T = void>(msg: string) {\n\t\treturn () => {\n\t\t\tthrow new DestructionError(msg)\n\t\t}\n\t}\n\tconstructor(msg: string) {\n\t\tsuper(`Object is destroyed. ${msg}`)\n\t\tthis.name = 'DestroyedAccessError'\n\t}\n}\nconst destroyedHandler = {\n\t[Symbol.toStringTag]: 'MutTs Destroyable',\n\tget: DestructionError.throw('Cannot access destroyed object'),\n\tset: DestructionError.throw('Cannot access destroyed object'),\n} as const\n\nabstract class AbstractDestroyable<Allocated> {\n\tabstract [destructor](allocated: Allocated): void\n\t[Symbol.dispose](): void {\n\t\tthis[destructor](this as unknown as Allocated)\n\t}\n}\n\ninterface Destructor<Allocated> {\n\tdestructor(allocated: Allocated): void\n}\n\nexport function Destroyable<\n\tT extends new (\n\t\t...args: any[]\n\t) => any,\n\tAllocated extends Partial<typeof this>,\n>(\n\tbase: T,\n\tdestructorObj: Destructor<Allocated>\n): (new (\n\t...args: ConstructorParameters<T>\n) => InstanceType<T> & { [allocatedValues]: Allocated }) & {\n\tdestroy(obj: InstanceType<T>): boolean\n\tisDestroyable(obj: InstanceType<T>): boolean\n}\n\nexport function Destroyable<Allocated extends Record<PropertyKey, any> = Record<PropertyKey, any>>(\n\tdestructorObj: Destructor<Allocated>\n): (new () => { [allocatedValues]: Allocated }) & {\n\tdestroy(obj: any): boolean\n\tisDestroyable(obj: any): boolean\n}\n\nexport function Destroyable<\n\tT extends new (\n\t\t...args: any[]\n\t) => any,\n\tAllocated extends Record<PropertyKey, any> = Record<PropertyKey, any>,\n>(\n\tbase: T\n): (new (\n\t...args: ConstructorParameters<T>\n) => AbstractDestroyable<Allocated> & InstanceType<T> & { [allocatedValues]: Allocated }) & {\n\tdestroy(obj: InstanceType<T>): boolean\n\tisDestroyable(obj: InstanceType<T>): boolean\n}\n\nexport function Destroyable<\n\tAllocated extends Record<PropertyKey, any> = Record<PropertyKey, any>,\n>(): abstract new () => (AbstractDestroyable<Allocated> & {\n\t[allocatedValues]: Allocated\n}) & {\n\tdestroy(obj: any): boolean\n\tisDestroyable(obj: any): boolean\n}\n\nexport function Destroyable<\n\tT extends new (\n\t\t...args: any[]\n\t) => any,\n\tAllocated extends Record<PropertyKey, any> = Record<PropertyKey, any>,\n>(base?: T | Destructor<Allocated>, destructorObj?: Destructor<Allocated>) {\n\tif (base && typeof base !== 'function') {\n\t\tdestructorObj = base as Destructor<Allocated>\n\t\tbase = undefined\n\t}\n\tif (!base) {\n\t\tbase = class {} as T\n\t}\n\n\treturn class Destroyable extends (base as T) {\n\t\tstatic readonly destructors = new WeakMap<any, () => void>()\n\t\tstatic destroy(obj: Destroyable) {\n\t\t\tconst destructor = Destroyable.destructors.get(obj)\n\t\t\tif (!destructor) return false\n\t\t\tfr.unregister(obj)\n\t\t\tDestroyable.destructors.delete(obj)\n\t\t\tObject.setPrototypeOf(obj, new Proxy({}, destroyedHandler))\n\t\t\t// Clear all own properties\n\t\t\tfor (const key of Object.getOwnPropertyNames(obj)) {\n\t\t\t\tdelete (obj as any)[key]\n\t\t\t}\n\t\t\tdestructor()\n\t\t\treturn true\n\t\t}\n\t\tstatic isDestroyable(obj: Destroyable) {\n\t\t\treturn Destroyable.destructors.has(obj)\n\t\t}\n\n\t\tdeclare [forwardProperties]: PropertyKey[]\n\t\treadonly [allocatedValues]: Allocated\n\t\tconstructor(...args: any[]) {\n\t\t\tsuper(...args)\n\t\t\tconst allocated = {} as Allocated\n\t\t\tthis[allocatedValues] = allocated\n\t\t\t// @ts-expect-error `this` is an AbstractDestroyable\n\t\t\tconst myDestructor = destructorObj?.destructor ?? this[destructor]\n\t\t\tif (!myDestructor) {\n\t\t\t\tthrow new DestructionError('Destructor is not defined')\n\t\t\t}\n\t\t\tfunction destruction() {\n\t\t\t\tmyDestructor(allocated)\n\t\t\t}\n\t\t\tDestroyable.destructors.set(this, destruction)\n\t\t\tfr.register(this, destruction, this)\n\t\t}\n\t}\n}\n\nconst forwardProperties = Symbol('forwardProperties')\nexport const allocated = decorator({\n\tsetter(original, propertyKey) {\n\t\treturn function (value) {\n\t\t\tthis[allocatedValues][propertyKey] = value\n\t\t\treturn original.call(this, value)\n\t\t}\n\t},\n})\n\nexport function callOnGC(cb: () => void) {\n\tlet called = false\n\tconst forward = () => {\n\t\tif (called) return\n\t\tcalled = true\n\t\tcb()\n\t}\n\tfr.register(forward, cb, cb)\n\treturn forward\n}\n\n// Context Manager Protocol for `with` statement integration\nexport interface ContextManager<T = any> {\n\t[Symbol.dispose](): void\n\tvalue?: T\n}\n"],"names":["decorator"],"mappings":";;;;AAEA;AACA,MAAM,EAAE,GAAG,IAAI,oBAAoB,CAAa,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;MAC9C,UAAU,GAAG,MAAM,CAAC,YAAY;MAChC,eAAe,GAAG,MAAM,CAAC,WAAW;AAC3C,MAAO,gBAAiB,SAAQ,KAAK,CAAA;IAC1C,OAAO,KAAK,CAAY,GAAW,EAAA;AAClC,QAAA,OAAO,MAAK;AACX,YAAA,MAAM,IAAI,gBAAgB,CAAC,GAAG,CAAC;AAChC,QAAA,CAAC;IACF;AACA,IAAA,WAAA,CAAY,GAAW,EA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,EAAE,CAAC;AAC5B,IAAA,OAAO,OAAO;AACf;;;;;;;;;"}
1
+ {"version":3,"file":"destroyable.js","sources":["../src/destroyable.ts"],"sourcesContent":["import { decorator } from './decorator'\n\n// Integrated with `using` statement via Symbol.dispose\nconst fr = new FinalizationRegistry<() => void>((f) => f())\n/**\n * Symbol for marking destructor methods\n */\nexport const destructor = Symbol('destructor')\n/**\n * Symbol for accessing allocated values in destroyable objects\n */\nexport const allocatedValues = Symbol('allocated')\n/**\n * Error thrown when attempting to access a destroyed object\n */\nexport class DestructionError extends Error {\n\tstatic throw<_T = void>(msg: string) {\n\t\treturn () => {\n\t\t\tthrow new DestructionError(msg)\n\t\t}\n\t}\n\tconstructor(msg: string) {\n\t\tsuper(`Object is destroyed. ${msg}`)\n\t\tthis.name = 'DestroyedAccessError'\n\t}\n}\nconst destroyedHandler = {\n\t[Symbol.toStringTag]: 'MutTs Destroyable',\n\tget: DestructionError.throw('Cannot access destroyed object'),\n\tset: DestructionError.throw('Cannot access destroyed object'),\n} as const\n\nabstract class AbstractDestroyable<Allocated> {\n\tabstract [destructor](allocated: Allocated): void\n\t[Symbol.dispose](): void {\n\t\tthis[destructor](this as unknown as Allocated)\n\t}\n}\n\ninterface Destructor<Allocated> {\n\tdestructor(allocated: Allocated): void\n}\n\n/**\n * Creates a destroyable class with a base class and destructor object\n * @param base - The base class to extend\n * @param destructorObj - Object containing the destructor method\n * @returns A destroyable class with static destroy and isDestroyable methods\n */\nexport function Destroyable<\n\tT extends new (\n\t\t...args: any[]\n\t) => any,\n\tAllocated extends Partial<typeof this>,\n>(\n\tbase: T,\n\tdestructorObj: Destructor<Allocated>\n): (new (\n\t...args: ConstructorParameters<T>\n) => InstanceType<T> & { [allocatedValues]: Allocated }) & {\n\tdestroy(obj: InstanceType<T>): boolean\n\tisDestroyable(obj: InstanceType<T>): boolean\n}\n\n/**\n * Creates a destroyable class with only a destructor object (no base class)\n * @param destructorObj - Object containing the destructor method\n * @returns A destroyable class with static destroy and isDestroyable methods\n */\nexport function Destroyable<Allocated extends Record<PropertyKey, any> = Record<PropertyKey, any>>(\n\tdestructorObj: Destructor<Allocated>\n): (new () => { [allocatedValues]: Allocated }) & {\n\tdestroy(obj: any): boolean\n\tisDestroyable(obj: any): boolean\n}\n\n/**\n * Creates a destroyable class with a base class (requires [destructor] method)\n * @param base - The base class to extend\n * @returns A destroyable class with static destroy and isDestroyable methods\n */\nexport function Destroyable<\n\tT extends new (\n\t\t...args: any[]\n\t) => any,\n\tAllocated extends Record<PropertyKey, any> = Record<PropertyKey, any>,\n>(\n\tbase: T\n): (new (\n\t...args: ConstructorParameters<T>\n) => AbstractDestroyable<Allocated> & InstanceType<T> & { [allocatedValues]: Allocated }) & {\n\tdestroy(obj: InstanceType<T>): boolean\n\tisDestroyable(obj: InstanceType<T>): boolean\n}\n\n/**\n * Creates an abstract destroyable base class\n * @returns An abstract destroyable class with static destroy and isDestroyable methods\n */\nexport function Destroyable<\n\tAllocated extends Record<PropertyKey, any> = Record<PropertyKey, any>,\n>(): abstract new () => (AbstractDestroyable<Allocated> & {\n\t[allocatedValues]: Allocated\n}) & {\n\tdestroy(obj: any): boolean\n\tisDestroyable(obj: any): boolean\n}\n\nexport function Destroyable<\n\tT extends new (\n\t\t...args: any[]\n\t) => any,\n\tAllocated extends Record<PropertyKey, any> = Record<PropertyKey, any>,\n>(base?: T | Destructor<Allocated>, destructorObj?: Destructor<Allocated>) {\n\tif (base && typeof base !== 'function') {\n\t\tdestructorObj = base as Destructor<Allocated>\n\t\tbase = undefined\n\t}\n\tif (!base) {\n\t\tbase = class {} as T\n\t}\n\n\treturn class Destroyable extends (base as T) {\n\t\tstatic readonly destructors = new WeakMap<any, () => void>()\n\t\tstatic destroy(obj: Destroyable) {\n\t\t\tconst destructor = Destroyable.destructors.get(obj)\n\t\t\tif (!destructor) return false\n\t\t\tfr.unregister(obj)\n\t\t\tDestroyable.destructors.delete(obj)\n\t\t\tObject.setPrototypeOf(obj, new Proxy({}, destroyedHandler))\n\t\t\t// Clear all own properties\n\t\t\tfor (const key of Object.getOwnPropertyNames(obj)) {\n\t\t\t\tdelete (obj as any)[key]\n\t\t\t}\n\t\t\tdestructor()\n\t\t\treturn true\n\t\t}\n\t\tstatic isDestroyable(obj: Destroyable) {\n\t\t\treturn Destroyable.destructors.has(obj)\n\t\t}\n\n\t\tdeclare [forwardProperties]: PropertyKey[]\n\t\treadonly [allocatedValues]: Allocated\n\t\tconstructor(...args: any[]) {\n\t\t\tsuper(...args)\n\t\t\tconst allocated = {} as Allocated\n\t\t\tthis[allocatedValues] = allocated\n\t\t\t// @ts-expect-error `this` is an AbstractDestroyable\n\t\t\tconst myDestructor = destructorObj?.destructor ?? this[destructor]\n\t\t\tif (!myDestructor) {\n\t\t\t\tthrow new DestructionError('Destructor is not defined')\n\t\t\t}\n\t\t\tfunction destruction() {\n\t\t\t\tmyDestructor(allocated)\n\t\t\t}\n\t\t\tDestroyable.destructors.set(this, destruction)\n\t\t\tfr.register(this, destruction, this)\n\t\t}\n\t}\n}\n\nconst forwardProperties = Symbol('forwardProperties')\n/**\n * Decorator that marks properties to be stored in the allocated object and passed to the destructor\n * Use with accessor properties or explicit get/set pairs\n */\nexport const allocated = decorator({\n\tsetter(original, propertyKey) {\n\t\treturn function (value) {\n\t\t\tthis[allocatedValues][propertyKey] = value\n\t\t\treturn original.call(this, value)\n\t\t}\n\t},\n})\n\n/**\n * Registers a callback to be called when an object is garbage collected\n * @param cb - The callback function to execute on garbage collection\n * @returns The object whose reference can be collected\n */\nexport function callOnGC(cb: () => void) {\n\tlet called = false\n\tconst forward = () => {\n\t\tif (called) return\n\t\tcalled = true\n\t\tcb()\n\t}\n\tfr.register(forward, cb, cb)\n\treturn forward\n}\n\n/**\n * Context Manager Protocol for `using` statement integration\n * Provides automatic resource cleanup when used with the `using` statement\n */\nexport interface ContextManager<T = any> {\n\t[Symbol.dispose](): void\n\tvalue?: T\n}\n"],"names":["decorator"],"mappings":";;;;AAEA;AACA,MAAM,EAAE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AC,eAAe,CAAC,CAAC,WAAW,CAAC,GAAG,KAAK;YAC1C,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC;AAClC,QAAA,CAAC;IACF,CAAC;AACD,CAAA;AAED;;;;AAIG;AACG,SAAU,QAAQ,CAAC,EAAc,EAAA;IACtC,IAAI,MAAM,GAAG,KAAK;IAClB,MAAM,OAAO,GAAG,MAAK;AACpB,QAAA,IAAI,MAAM;YAAE;QACZ,MAAM,GAAG,IAAI;AACb,QAAA,EAAE,EAAE;AACL,IAAA,CAAC;IACD,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,EAAE,EAAE,CAAC;AAC5B,IAAA,OAAO,OAAO;AACf;;;;;;;;;"}
@@ -1,4 +1,12 @@
1
- declare class Eventful<Events extends Record<string, (...args: any[]) => void>> {
1
+ /**
2
+ * Base type for event maps - all event handlers must be functions
3
+ */
4
+ type EventsBase = Record<string, (...args: any[]) => void>;
5
+ /**
6
+ * A type-safe event system that provides a clean API for event handling
7
+ * @template Events - The event map defining event names and their handler signatures
8
+ */
9
+ declare class Eventful<Events extends EventsBase> {
2
10
  #private;
3
11
  hook(cb: <EventType extends keyof Events>(event: EventType, ...args: Parameters<Events[EventType]>) => void): () => void;
4
12
  on(events: Partial<Events>): void;
@@ -9,3 +17,4 @@ declare class Eventful<Events extends Record<string, (...args: any[]) => void>>
9
17
  }
10
18
 
11
19
  export { Eventful };
20
+ export type { EventsBase };
@@ -1,32 +1,10 @@
1
- /******************************************************************************
2
- Copyright (c) Microsoft Corporation.
3
-
4
- Permission to use, copy, modify, and/or distribute this software for any
5
- purpose with or without fee is hereby granted.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
- PERFORMANCE OF THIS SOFTWARE.
14
- ***************************************************************************** */
15
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
16
-
17
-
18
- function __classPrivateFieldGet(receiver, state, kind, f) {
19
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
20
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
21
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
22
- }
23
-
24
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
25
- var e = new Error(message);
26
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
27
- };
1
+ import { _ as __classPrivateFieldGet } from './chunks/_tslib-CMEnd0VE.esm.js';
28
2
 
29
3
  var _Eventful_events, _Eventful_hooks;
4
+ /**
5
+ * A type-safe event system that provides a clean API for event handling
6
+ * @template Events - The event map defining event names and their handler signatures
7
+ */
30
8
  class Eventful {
31
9
  constructor() {
32
10
  _Eventful_events.set(this, new Map());
@@ -1 +1 @@
1
- {"version":3,"file":"eventful.esm.js","sources":["../src/eventful.ts"],"sourcesContent":["export class Eventful<Events extends Record<string, (...args: any[]) => void>> {\n\treadonly #events = new Map<keyof Events, ((...args: any[]) => void)[]>()\n\treadonly #hooks = [] as ((...args: any[]) => void)[]\n\n\tpublic hook(\n\t\tcb: <EventType extends keyof Events>(\n\t\t\tevent: EventType,\n\t\t\t...args: Parameters<Events[EventType]>\n\t\t) => void\n\t): () => void {\n\t\tif (!this.#hooks.includes(cb)) this.#hooks.push(cb)\n\t\treturn () => {\n\t\t\tthis.#hooks.splice(this.#hooks.indexOf(cb), 1)\n\t\t}\n\t}\n\n\tpublic on(events: Partial<Events>): void\n\tpublic on<EventType extends keyof Events>(event: EventType, cb: Events[EventType]): () => void\n\tpublic on<EventType extends keyof Events>(\n\t\teventOrEvents: EventType | Partial<Events>,\n\t\tcb?: Events[EventType]\n\t): () => void {\n\t\tif (typeof eventOrEvents === 'object') {\n\t\t\tfor (const e of Object.keys(eventOrEvents) as (keyof Events)[]) {\n\t\t\t\tthis.on(e, eventOrEvents[e]!)\n\t\t\t}\n\t\t} else if (cb !== undefined) {\n\t\t\tlet callbacks = this.#events.get(eventOrEvents)\n\t\t\tif (!callbacks) {\n\t\t\t\tcallbacks = []\n\t\t\t\tthis.#events.set(eventOrEvents, callbacks)\n\t\t\t}\n\t\t\tcallbacks.push(cb)\n\t\t}\n\t\t// @ts-expect-error Generic case leads to generic case\n\t\treturn () => this.off(eventOrEvents, cb)\n\t}\n\tpublic off(events: Partial<Events>): void\n\tpublic off<EventType extends keyof Events>(event: EventType, cb?: Events[EventType]): void\n\tpublic off<EventType extends keyof Events>(\n\t\teventOrEvents: EventType | Partial<Events>,\n\t\tcb?: Events[EventType]\n\t): void {\n\t\tif (typeof eventOrEvents === 'object') {\n\t\t\tfor (const e of Object.keys(eventOrEvents) as (keyof Events)[]) {\n\t\t\t\tthis.off(e, eventOrEvents[e])\n\t\t\t}\n\t\t} else if (cb !== null && cb !== undefined) {\n\t\t\tconst callbacks = this.#events.get(eventOrEvents)\n\t\t\tif (callbacks) {\n\t\t\t\tthis.#events.set(\n\t\t\t\t\teventOrEvents,\n\t\t\t\t\tcallbacks.filter((c) => c !== cb)\n\t\t\t\t)\n\t\t\t}\n\t\t} else {\n\t\t\t// Remove all listeners for this event\n\t\t\tthis.#events.delete(eventOrEvents)\n\t\t}\n\t}\n\tpublic emit<EventType extends keyof Events>(\n\t\tevent: EventType,\n\t\t...args: Parameters<Events[EventType]>\n\t) {\n\t\tconst callbacks = this.#events.get(event)\n\t\tif (callbacks) for (const cb of callbac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AA,CAAO;YAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;IAC5D;AACA;;;;;"}
1
+ {"version":3,"file":"eventful.esm.js","sources":["../src/eventful.ts"],"sourcesContent":["/**\n * Base type for event maps - all event handlers must be functions\n */\nexport type EventsBase = Record<string, (...args: any[]) => void>\n/**\n * A type-safe event system that provides a clean API for event handling\n * @template Events - The event map defining event names and their handler signatures\n */\nexport class Eventful<Events extends EventsBase> {\n\treadonly #events = new Map<keyof Events, ((...args: any[]) => void)[]>()\n\treadonly #hooks = [] as ((...args: any[]) => void)[]\n\n\tpublic hook(\n\t\tcb: <EventType extends keyof Events>(\n\t\t\tevent: EventType,\n\t\t\t...args: Parameters<Events[EventType]>\n\t\t) => void\n\t): () => void {\n\t\tif (!this.#hooks.includes(cb)) this.#hooks.push(cb)\n\t\treturn () => {\n\t\t\tthis.#hooks.splice(this.#hooks.indexOf(cb), 1)\n\t\t}\n\t}\n\n\tpublic on(events: Partial<Events>): void\n\tpublic on<EventType extends keyof Events>(event: EventType, cb: Events[EventType]): () => void\n\tpublic on<EventType extends keyof Events>(\n\t\teventOrEvents: EventType | Partial<Events>,\n\t\tcb?: Events[EventType]\n\t): () => void {\n\t\tif (typeof eventOrEvents === 'object') {\n\t\t\tfor (const e of Object.keys(eventOrEvents) as (keyof Events)[]) {\n\t\t\t\tthis.on(e, eventOrEvents[e]!)\n\t\t\t}\n\t\t} else if (cb !== undefined) {\n\t\t\tlet callbacks = this.#events.get(eventOrEvents)\n\t\t\tif (!callbacks) {\n\t\t\t\tcallbacks = []\n\t\t\t\tthis.#events.set(eventOrEvents, callbacks)\n\t\t\t}\n\t\t\tcallbacks.push(cb)\n\t\t}\n\t\t// @ts-expect-error Generic case leads to generic case\n\t\treturn () => this.off(eventOrEvents, cb)\n\t}\n\tpublic off(events: Partial<Events>): void\n\tpublic off<EventType extends keyof Events>(event: EventType, cb?: Events[EventType]): void\n\tpublic off<EventType extends keyof Events>(\n\t\teventOrEvents: EventType | Partial<Events>,\n\t\tcb?: Events[EventType]\n\t): void {\n\t\tif (typeof eventOrEvents === 'object') {\n\t\t\tfor (const e of Object.keys(eventOrEvents) as (keyof Events)[]) {\n\t\t\t\tthis.off(e, eventOrEvents[e])\n\t\t\t}\n\t\t} else if (cb !== null && cb !== undefined) {\n\t\t\tconst callbacks = this.#events.get(eventOrEvents)\n\t\t\tif (callbacks) {\n\t\t\t\tthis.#events.set(\n\t\t\t\t\teventOrEvents,\n\t\t\t\t\tcallbacks.filter((c) => c !== cb)\n\t\t\t\t)\n\t\t\t}\n\t\t} else {\n\t\t\t// Remove all listeners for this event\n\t\t\tthis.#events.delete(eventOrEvents)\n\t\t}\n\t}\n\tpublic emit<EventType extends keyof Events>(\n\t\tevent: EventType,\n\t\t...args: Parameters<Events[EventType]>\n\t) {\n\t\tconst callbacks = this.#events.get(event)\n\t\tif (callbacks) for (const cb of callbacks) cb.apply(this, args)\n\t\tfor (const cb of this.#hooks) cb.call(this, event, ...args)\n\t}\n}\n"],"names":[],"mappings":";;;AAIA;;;AAGG;MACU,QAAQ,CAAA;AAArB,IAAA,WAAA,GAAA;QACU,gBAAA,CAAA,GAAA,CAAA,IAAA,EAAU,IAAI,GAAG,EAA8C,CAAA;AAC/D,QAAA,eAAA,CAAA,GAAA,CAAA,IAAA,EAAS,EAAkC,CAAA;IAkErD;AAhEQ,IAAA,IAAI,CACV,EAGS,EAAA;QAET,IAAI,CAAC,uBAAA,IAAI,EAAA,eAAA,EAAA,GAAA,CAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;AAAE,YAAA,sBAAA,CAAA,IAAI,EAAA,eAAA,EAAA,GAAA,CAAO,CAAC,IAAI,CAAC,EAAE,CAAC;AACnD,QAAA,OAAO,MAAK;AACX,YAAA,sBAAA,CAAA,IAAI,EAAA,eAAA,EAAA,GAAA,CAAO,CAAC,MAAM,CAAC,uBAAA,IAAI,EAAA,eAAA,EAAA,GAAA,CAAO,CAAC,O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AAa,EACb,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CACjC;YACF;QACD;aAAO;;AAEN,YAAA,sBAAA,CAAA,IAAI,EAAA,gBAAA,EAAA,GAAA,CAAQ,CAAC,MAAM,CAAC,aAAa,CAAC;QACnC;IACD;AACO,IAAA,IAAI,CACV,KAAgB,EAChB,GAAG,IAAmC,EAAA;QAEtC,MAAM,SAAS,GAAG,sBAAA,CAAA,IAAI,EAAA,gBAAA,EAAA,GAAA,CAAQ,CAAC,GAAG,CAAC,KAAK,CAAC;AACzC,QAAA,IAAI,SAAS;YAAE,KAAK,MAAM,EAAE,IAAI,SAAS;AAAE,gBAAA,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC;AAC/D,QAAA,KAAK,MAAM,EAAE,IAAI,sBAAA,CAAA,IAAI,EAAA,eAAA,EAAA,GAAA,CAAO;YAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;IAC5D;AACA;;;;;"}
package/dist/eventful.js CHANGED
@@ -1,44 +1,22 @@
1
1
  'use strict';
2
2
 
3
- /******************************************************************************
4
- Copyright (c) Microsoft Corporation.
5
-
6
- Permission to use, copy, modify, and/or distribute this software for any
7
- purpose with or without fee is hereby granted.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
- PERFORMANCE OF THIS SOFTWARE.
16
- ***************************************************************************** */
17
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
18
-
19
-
20
- function __classPrivateFieldGet(receiver, state, kind, f) {
21
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
22
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
23
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
24
- }
25
-
26
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
27
- var e = new Error(message);
28
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
29
- };
3
+ var _tslib = require('./chunks/_tslib-C-cuVLvZ.js');
30
4
 
31
5
  var _Eventful_events, _Eventful_hooks;
6
+ /**
7
+ * A type-safe event system that provides a clean API for event handling
8
+ * @template Events - The event map defining event names and their handler signatures
9
+ */
32
10
  class Eventful {
33
11
  constructor() {
34
12
  _Eventful_events.set(this, new Map());
35
13
  _Eventful_hooks.set(this, []);
36
14
  }
37
15
  hook(cb) {
38
- if (!__classPrivateFieldGet(this, _Eventful_hooks, "f").includes(cb))
39
- __classPrivateFieldGet(this, _Eventful_hooks, "f").push(cb);
16
+ if (!_tslib.__classPrivateFieldGet(this, _Eventful_hooks, "f").includes(cb))
17
+ _tslib.__classPrivateFieldGet(this, _Eventful_hooks, "f").push(cb);
40
18
  return () => {
41
- __classPrivateFieldGet(this, _Eventful_hooks, "f").splice(__classPrivateFieldGet(this, _Eventful_hooks, "f").indexOf(cb), 1);
19
+ _tslib.__classPrivateFieldGet(this, _Eventful_hooks, "f").splice(_tslib.__classPrivateFieldGet(this, _Eventful_hooks, "f").indexOf(cb), 1);
42
20
  };
43
21
  }
44
22
  on(eventOrEvents, cb) {
@@ -48,10 +26,10 @@ class Eventful {
48
26
  }
49
27
  }
50
28
  else if (cb !== undefined) {
51
- let callbacks = __classPrivateFieldGet(this, _Eventful_events, "f").get(eventOrEvents);
29
+ let callbacks = _tslib.__classPrivateFieldGet(this, _Eventful_events, "f").get(eventOrEvents);
52
30
  if (!callbacks) {
53
31
  callbacks = [];
54
- __classPrivateFieldGet(this, _Eventful_events, "f").set(eventOrEvents, callbacks);
32
+ _tslib.__classPrivateFieldGet(this, _Eventful_events, "f").set(eventOrEvents, callbacks);
55
33
  }
56
34
  callbacks.push(cb);
57
35
  }
@@ -65,22 +43,22 @@ class Eventful {
65
43
  }
66
44
  }
67
45
  else if (cb !== null && cb !== undefined) {
68
- const callbacks = __classPrivateFieldGet(this, _Eventful_events, "f").get(eventOrEvents);
46
+ const callbacks = _tslib.__classPrivateFieldGet(this, _Eventful_events, "f").get(eventOrEvents);
69
47
  if (callbacks) {
70
- __classPrivateFieldGet(this, _Eventful_events, "f").set(eventOrEvents, callbacks.filter((c) => c !== cb));
48
+ _tslib.__classPrivateFieldGet(this, _Eventful_events, "f").set(eventOrEvents, callbacks.filter((c) => c !== cb));
71
49
  }
72
50
  }
73
51
  else {
74
52
  // Remove all listeners for this event
75
- __classPrivateFieldGet(this, _Eventful_events, "f").delete(eventOrEvents);
53
+ _tslib.__classPrivateFieldGet(this, _Eventful_events, "f").delete(eventOrEvents);
76
54
  }
77
55
  }
78
56
  emit(event, ...args) {
79
- const callbacks = __classPrivateFieldGet(this, _Eventful_events, "f").get(event);
57
+ const callbacks = _tslib.__classPrivateFieldGet(this, _Eventful_events, "f").get(event);
80
58
  if (callbacks)
81
59
  for (const cb of callbacks)
82
60
  cb.apply(this, args);
83
- for (const cb of __classPrivateFieldGet(this, _Eventful_hooks, "f"))
61
+ for (const cb of _tslib.__classPrivateFieldGet(this, _Eventful_hooks, "f"))
84
62
  cb.call(this, event, ...args);
85
63
  }
86
64
  }
@@ -1 +1 @@
1
- {"version":3,"file":"eventful.js","sources":["../src/eventful.ts"],"sourcesContent":["export class Eventful<Events extends Record<string, (...args: any[]) => void>> {\n\treadonly #events = new Map<keyof Events, ((...args: any[]) => void)[]>()\n\treadonly #hooks = [] as ((...args: any[]) => void)[]\n\n\tpublic hook(\n\t\tcb: <EventType extends keyof Events>(\n\t\t\tevent: EventType,\n\t\t\t...args: Parameters<Events[EventType]>\n\t\t) => void\n\t): () => void {\n\t\tif (!this.#hooks.includes(cb)) this.#hooks.push(cb)\n\t\treturn () => {\n\t\t\tthis.#hooks.splice(this.#hooks.indexOf(cb), 1)\n\t\t}\n\t}\n\n\tpublic on(events: Partial<Events>): void\n\tpublic on<EventType extends keyof Events>(event: EventType, cb: Events[EventType]): () => void\n\tpublic on<EventType extends keyof Events>(\n\t\teventOrEvents: EventType | Partial<Events>,\n\t\tcb?: Events[EventType]\n\t): () => void {\n\t\tif (typeof eventOrEvents === 'object') {\n\t\t\tfor (const e of Object.keys(eventOrEvents) as (keyof Events)[]) {\n\t\t\t\tthis.on(e, eventOrEvents[e]!)\n\t\t\t}\n\t\t} else if (cb !== undefined) {\n\t\t\tlet callbacks = this.#events.get(eventOrEvents)\n\t\t\tif (!callbacks) {\n\t\t\t\tcallbacks = []\n\t\t\t\tthis.#events.set(eventOrEvents, callbacks)\n\t\t\t}\n\t\t\tcallbacks.push(cb)\n\t\t}\n\t\t// @ts-expect-error Generic case leads to generic case\n\t\treturn () => this.off(eventOrEvents, cb)\n\t}\n\tpublic off(events: Partial<Events>): void\n\tpublic off<EventType extends keyof Events>(event: EventType, cb?: Events[EventType]): void\n\tpublic off<EventType extends keyof Events>(\n\t\teventOrEvents: EventType | Partial<Events>,\n\t\tcb?: Events[EventType]\n\t): void {\n\t\tif (typeof eventOrEvents === 'object') {\n\t\t\tfor (const e of Object.keys(eventOrEvents) as (keyof Events)[]) {\n\t\t\t\tthis.off(e, eventOrEvents[e])\n\t\t\t}\n\t\t} else if (cb !== null && cb !== undefined) {\n\t\t\tconst callbacks = this.#events.get(eventOrEvents)\n\t\t\tif (callbacks) {\n\t\t\t\tthis.#events.set(\n\t\t\t\t\teventOrEvents,\n\t\t\t\t\tcallbacks.filter((c) => c !== cb)\n\t\t\t\t)\n\t\t\t}\n\t\t} else {\n\t\t\t// Remove all listeners for this event\n\t\t\tthis.#events.delete(eventOrEvents)\n\t\t}\n\t}\n\tpublic emit<EventType extends keyof Events>(\n\t\tevent: EventType,\n\t\t...args: Parameters<Events[EventType]>\n\t) {\n\t\tconst callbacks = this.#events.get(event)\n\t\tif (callbacks) for (const cb of callbacks) cb.apply(this, args)\n\t\tfor (const cb of this.#hooks) cb.call(this, event, ...args)\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAAa,QAAQ,CAAA;AAArB,IAAA,WAAA,GAAA;QACU,gBAAA,CAAA,GAAA,CAAA,IAAA,EAAU,IAAI,GAAG,EAA8C,CAAA;AAC/D,QAAA,eAAA,CAAA,GAAA,CAAA,IAAA,EAAS,EAAkC,CAAA;IAkErD;AAhEQ,IAAA,IAAI,CACV,EAGS,EAAA;QAET,IAAI,CAAC,uBAAA,IAAI,EAAA,eAAA,EAAA,GAAA,CAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;AAAE,YAAA,sBAAA,CAAA,IAAI,EAAA,eAAA,EAAA,GAAA,CAAO,CAAC,IAAI,CAAC,EAAE,CAAC;AACnD,QAAA,OAAO,MAAK;AACX,YAAA,sBAAA,CAAA,IAAI,EAAA,eAAA,EAAA,GAAA,CAAO,CAAC,MAAM,CAAC,uBAAA,IAAI,EAAA,eAAA,EAAA,GAAA,CAAO,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;AAC/C,QAAA,CAAC;IACF;IAIO,EAAE,CACR,aAA0C,EAC1C,EAAsB,EAAA;AAEtB,QAAA,IAAI,OAAO,aAAa,KAAK,QAAQ,EAAE;YACtC,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,aAAa,CAAqB,EAAE;gBAC/D,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAE,CAAC;YAC9B;QACD;AAAO,aAAA,IA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CAAC,GAAG,CAAC,KAAK,CAAC;AACzC,QAAA,IAAI,SAAS;YAAE,KAAK,MAAM,EAAE,IAAI,SAAS;AAAE,gBAAA,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC;AAC/D,QAAA,KAAK,MAAM,EAAE,IAAI,sBAAA,CAAA,IAAI,EAAA,eAAA,EAAA,GAAA,CAAO;YAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;IAC5D;AACA;;;;;"}
1
+ {"version":3,"file":"eventful.js","sources":["../src/eventful.ts"],"sourcesContent":["/**\n * Base type for event maps - all event handlers must be functions\n */\nexport type EventsBase = Record<string, (...args: any[]) => void>\n/**\n * A type-safe event system that provides a clean API for event handling\n * @template Events - The event map defining event names and their handler signatures\n */\nexport class Eventful<Events extends EventsBase> {\n\treadonly #events = new Map<keyof Events, ((...args: any[]) => void)[]>()\n\treadonly #hooks = [] as ((...args: any[]) => void)[]\n\n\tpublic hook(\n\t\tcb: <EventType extends keyof Events>(\n\t\t\tevent: EventType,\n\t\t\t...args: Parameters<Events[EventType]>\n\t\t) => void\n\t): () => void {\n\t\tif (!this.#hooks.includes(cb)) this.#hooks.push(cb)\n\t\treturn () => {\n\t\t\tthis.#hooks.splice(this.#hooks.indexOf(cb), 1)\n\t\t}\n\t}\n\n\tpublic on(events: Partial<Events>): void\n\tpublic on<EventType extends keyof Events>(event: EventType, cb: Events[EventType]): () => void\n\tpublic on<EventType extends keyof Events>(\n\t\teventOrEvents: EventType | Partial<Events>,\n\t\tcb?: Events[EventType]\n\t): () => void {\n\t\tif (typeof eventOrEvents === 'object') {\n\t\t\tfor (const e of Object.keys(eventOrEvents) as (keyof Events)[]) {\n\t\t\t\tthis.on(e, eventOrEvents[e]!)\n\t\t\t}\n\t\t} else if (cb !== undefined) {\n\t\t\tlet callbacks = this.#events.get(eventOrEvents)\n\t\t\tif (!callbacks) {\n\t\t\t\tcallbacks = []\n\t\t\t\tthis.#events.set(eventOrEvents, callbacks)\n\t\t\t}\n\t\t\tcallbacks.push(cb)\n\t\t}\n\t\t// @ts-expect-error Generic case leads to generic case\n\t\treturn () => this.off(eventOrEvents, cb)\n\t}\n\tpublic off(events: Partial<Events>): void\n\tpublic off<EventType extends keyof Events>(event: EventType, cb?: Events[EventType]): void\n\tpublic off<EventType extends keyof Events>(\n\t\teventOrEvents: EventType | Partial<Events>,\n\t\tcb?: Events[EventType]\n\t): void {\n\t\tif (typeof eventOrEvents === 'object') {\n\t\t\tfor (const e of Object.keys(eventOrEvents) as (keyof Events)[]) {\n\t\t\t\tthis.off(e, eventOrEvents[e])\n\t\t\t}\n\t\t} else if (cb !== null && cb !== undefined) {\n\t\t\tconst callbacks = this.#events.get(eventOrEvents)\n\t\t\tif (callbacks) {\n\t\t\t\tthis.#events.set(\n\t\t\t\t\teventOrEvents,\n\t\t\t\t\tcallbacks.filter((c) => c !== cb)\n\t\t\t\t)\n\t\t\t}\n\t\t} else {\n\t\t\t// Remove all listeners for this event\n\t\t\tthis.#events.delete(eventOrEvents)\n\t\t}\n\t}\n\tpublic emit<EventType extends keyof Events>(\n\t\tevent: EventType,\n\t\t...args: Parameters<Events[EventType]>\n\t) {\n\t\tconst callbacks = this.#events.get(event)\n\t\tif (callbacks) for (const cb of callbacks) cb.apply(this, args)\n\t\tfor (const cb of this.#hooks) cb.call(this, event, ...args)\n\t}\n}\n"],"names":["__classPrivateFieldGet"],"mappings":";;;;;AAIA;;;AAGG;MACU,QAAQ,CAAA;AAArB,IAAA,WAAA,GAAA;QACU,gBAAA,CAAA,GAAA,CAAA,IAAA,EAAU,IAAI,GAAG,EAA8C,CAAA;AAC/D,QAAA,eAAA,CAAA,GAAA,CAAA,IAAA,EAAS,EAAkC,CAAA;IAkErD;AAhEQ,IAAA,IAAI,CACV,EAGS,EAAA;QAET,IAAI,CAACA,8BAAA,IAAI,EAAA,eAAA,EAAA,GAAA,CAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;AA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ACD;aAAO,IAAI,EAAE,KAAK,IAAI,IAAI,EAAE,KAAK,SAAS,EAAE;YAC3C,MAAM,SAAS,GAAGA,6BAAA,CAAA,IAAI,EAAA,gBAAA,EAAA,GAAA,CAAQ,CAAC,GAAG,CAAC,aAAa,CAAC;YACjD,IAAI,SAAS,EAAE;gBACdA,6BAAA,CAAA,IAAI,wBAAQ,CAAC,GAAG,CACf,aAAa,EACb,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CACjC;YACF;QACD;aAAO;;AAEN,YAAAA,6BAAA,CAAA,IAAI,EAAA,gBAAA,EAAA,GAAA,CAAQ,CAAC,MAAM,CAAC,aAAa,CAAC;QACnC;IACD;AACO,IAAA,IAAI,CACV,KAAgB,EAChB,GAAG,IAAmC,EAAA;QAEtC,MAAM,SAAS,GAAGA,6BAAA,CAAA,IAAI,EAAA,gBAAA,EAAA,GAAA,CAAQ,CAAC,GAAG,CAAC,KAAK,CAAC;AACzC,QAAA,IAAI,SAAS;YAAE,KAAK,MAAM,EAAE,IAAI,SAAS;AAAE,gBAAA,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC;AAC/D,QAAA,KAAK,MAAM,EAAE,IAAIA,6BAAA,CAAA,IAAI,EAAA,eAAA,EAAA,GAAA,CAAO;YAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;IAC5D;AACA;;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,15 +1,64 @@
1
1
  export { Decorator, DecoratorDescription, DecoratorError, DecoratorFactory, GenericClassDecorator, LegacyClassDecorator, LegacyPropertyDecorator, ModernAccessorDecorator, ModernClassDecorator, ModernGetterDecorator, ModernMethodDecorator, ModernSetterDecorator, decorator, legacyDecorator, modernDecorator } from './decorator.js';
2
2
  export { ContextManager, Destroyable, DestructionError, allocated, allocatedValues, callOnGC, destructor } from './destroyable.js';
3
- export { Eventful } from './eventful.js';
3
+ export { Eventful, EventsBase } from './eventful.js';
4
4
  export { Indexable, getAt, setAt } from './indexable.js';
5
- export { ReactiveBase, ReactiveError, ScopedCallback, atomic, computed, effect, getState, immutables, invalidateComputed, isNonReactive, isReactive, profileInfo, reactive, reactiveOptions, unreactive, untracked, unwrap, watch } from './reactive.js';
5
+ export { Evolution, Reactive, ReactiveBase, ReactiveError, ScopedCallback, activeEffect, addBatchCleanup, atomic, cleanedBy, computed, effect, getState, immutables, invalidateComputed, isNonReactive, isReactive, profileInfo, reactive, reactiveOptions, trackEffect, unreactive, untracked, unwrap, watch } from './reactive.js';
6
6
  export { cache, cached, debounce, deprecated, describe, isCached, throttle } from './std-decorators.js';
7
7
 
8
+ /**
9
+ * A mixin function that takes a base class and returns a new class with mixed-in functionality
10
+ * @template Mixed - The functionality to be mixed in
11
+ */
12
+ type MixinFunction<Mixed> = <Base>(base: new (...args: any[]) => Base) => new (...args: any[]) => Base & Mixed;
13
+ /**
14
+ * A mixin class that can be used both as a base class and as a mixin function
15
+ * @template Mixed - The functionality to be mixed in
16
+ */
17
+ type MixinClass<Mixed> = new (...args: any[]) => Mixed;
18
+ /**
19
+ * Creates a mixin that can be used both as a class (extends) and as a function (mixin)
20
+ *
21
+ * This function supports:
22
+ * - Using mixins as base classes: `class MyClass extends MyMixin`
23
+ * - Using mixins as functions: `class MyClass extends MyMixin(SomeBase)`
24
+ * - Composing mixins: `const Composed = MixinA(MixinB)`
25
+ * - Type-safe property inference for all patterns
26
+ *
27
+ * @param mixinFunction - The function that creates the mixin
28
+ * @param unwrapFunction - Optional function to unwrap reactive objects for method calls
29
+ * @returns A mixin that can be used both as a class and as a function
30
+ */
31
+ declare function mixin<MixinFn extends (base: any) => new (...args: any[]) => any>(mixinFunction: MixinFn, unwrapFunction?: (obj: any) => any): (new (...args: any[]) => InstanceType<ReturnType<MixinFn>>) & (<Base>(base: abstract new (...args: any[]) => Base) => new (...args: any[]) => InstanceType<ReturnType<MixinFn>> & Base);
32
+
8
33
  type ElementTypes<T extends readonly unknown[]> = {
9
34
  [K in keyof T]: T[K] extends readonly (infer U)[] ? U : T[K];
10
35
  };
36
+ /**
37
+ * Combines multiple arrays into an array of tuples, stopping at the shortest array length
38
+ * @param args - Arrays to zip together
39
+ * @returns Array of tuples containing elements from each input array
40
+ */
11
41
  declare function zip<T extends (readonly unknown[])[]>(...args: T): ElementTypes<T>[];
42
+ /**
43
+ * Checks if a function is a constructor (class or constructor function)
44
+ * @param fn - The function to check
45
+ * @returns True if the function is a constructor
46
+ */
12
47
  declare function isConstructor(fn: Function): boolean;
48
+ /**
49
+ * Renames a function with a new name
50
+ * @param fct - The function to rename
51
+ * @param name - The new name for the function
52
+ * @returns The function with the new name
53
+ */
13
54
  declare function renamed<F extends Function>(fct: F, name: string): F;
55
+ declare function ReflectGet(obj: any, prop: any, receiver: any): any;
56
+ declare function ReflectSet(obj: any, prop: any, value: any, receiver: any): any;
57
+ declare function isOwnAccessor(obj: any, prop: any): boolean;
58
+ /**
59
+ * Check if an object is an object (not null, not primitive)
60
+ */
61
+ declare function isObject(obj: any): obj is object;
14
62
 
15
- export { isConstructor, renamed, zip };
63
+ export { ReflectGet, ReflectSet, isConstructor, isObject, isOwnAccessor, mixin, renamed, zip };
64
+ export type { MixinClass, MixinFunction };
package/dist/index.esm.js CHANGED
@@ -1,7 +1,8 @@
1
- export { D as DecoratorError, d as decorator, i as isConstructor, l as legacyDecorator, m as modernDecorator, r as renamed, z as zip } from './chunks/decorator-AbRkXM5O.esm.js';
1
+ export { D as DecoratorError, R as ReflectGet, a as ReflectSet, d as decorator, i as isConstructor, c as isObject, b as isOwnAccessor, l as legacyDecorator, m as modernDecorator, r as renamed, z as zip } from './chunks/decorator-GnHw1Az7.esm.js';
2
2
  export { Destroyable, DestructionError, allocated, allocatedValues, callOnGC, destructor } from './destroyable.esm.js';
3
3
  export { Eventful } from './eventful.esm.js';
4
4
  export { Indexable, getAt, setAt } from './indexable.esm.js';
5
- export { ReactiveBase, ReactiveError, atomic, computed, effect, getState, immutables, invalidateComputed, isNonReactive, isReactive, profileInfo, reactive, reactiveOptions, unreactive, untracked, unwrap, watch } from './reactive.esm.js';
5
+ export { R as Reactive, h as ReactiveBase, j as ReactiveError, a as activeEffect, b as addBatchCleanup, c as atomic, l as cleanedBy, n as computed, e as effect, g as getState, i as immutables, q as invalidateComputed, d as isNonReactive, f as isReactive, m as mixin, p as profileInfo, r as reactive, o as reactiveOptions, t as trackEffect, s as unreactive, u as untracked, k as unwrap, w as watch } from './chunks/index-DBScoeCX.esm.js';
6
6
  export { cache, cached, debounce, deprecated, describe, isCached, throttle } from './std-decorators.esm.js';
7
+ import './chunks/_tslib-CMEnd0VE.esm.js';
7
8
  //# sourceMappingURL=index.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
1
+ {"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
package/dist/index.js CHANGED
@@ -1,17 +1,22 @@
1
1
  'use strict';
2
2
 
3
- var decorator = require('./chunks/decorator-8qjFb7dw.js');
3
+ var decorator = require('./chunks/decorator-D4DU97Zg.js');
4
4
  var destroyable = require('./destroyable.js');
5
5
  var eventful = require('./eventful.js');
6
6
  var indexable = require('./indexable.js');
7
- var reactive = require('./reactive.js');
7
+ var reactive = require('./chunks/index-DOTmXL89.js');
8
8
  var stdDecorators = require('./std-decorators.js');
9
+ require('./chunks/_tslib-C-cuVLvZ.js');
9
10
 
10
11
 
11
12
 
12
13
  exports.DecoratorError = decorator.DecoratorError;
14
+ exports.ReflectGet = decorator.ReflectGet;
15
+ exports.ReflectSet = decorator.ReflectSet;
13
16
  exports.decorator = decorator.decorator;
14
17
  exports.isConstructor = decorator.isConstructor;
18
+ exports.isObject = decorator.isObject;
19
+ exports.isOwnAccessor = decorator.isOwnAccessor;
15
20
  exports.legacyDecorator = decorator.legacyDecorator;
16
21
  exports.modernDecorator = decorator.modernDecorator;
17
22
  exports.renamed = decorator.renamed;
@@ -26,9 +31,16 @@ exports.Eventful = eventful.Eventful;
26
31
  exports.Indexable = indexable.Indexable;
27
32
  exports.getAt = indexable.getAt;
28
33
  exports.setAt = indexable.setAt;
34
+ exports.Reactive = reactive.Reactive;
29
35
  exports.ReactiveBase = reactive.ReactiveBase;
30
36
  exports.ReactiveError = reactive.ReactiveError;
37
+ Object.defineProperty(exports, "activeEffect", {
38
+ enumerable: true,
39
+ get: function () { return reactive.activeEffect; }
40
+ });
41
+ exports.addBatchCleanup = reactive.addBatchCleanup;
31
42
  exports.atomic = reactive.atomic;
43
+ exports.cleanedBy = reactive.cleanedBy;
32
44
  exports.computed = reactive.computed;
33
45
  exports.effect = reactive.effect;
34
46
  exports.getState = reactive.getState;
@@ -36,9 +48,11 @@ exports.immutables = reactive.immutables;
36
48
  exports.invalidateComputed = reactive.invalidateComputed;
37
49
  exports.isNonReactive = reactive.isNonReactive;
38
50
  exports.isReactive = reactive.isReactive;
51
+ exports.mixin = reactive.mixin;
39
52
  exports.profileInfo = reactive.profileInfo;
40
53
  exports.reactive = reactive.reactive;
41
- exports.reactiveOptions = reactive.reactiveOptions;
54
+ exports.reactiveOptions = reactive.options;
55
+ exports.trackEffect = reactive.trackEffect;
42
56
  exports.unreactive = reactive.unreactive;
43
57
  exports.untracked = reactive.untracked;
44
58
  exports.unwrap = reactive.unwrap;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,4 +1,10 @@
1
+ /**
2
+ * Symbol for defining custom getter logic for numeric index access
3
+ */
1
4
  declare const getAt: unique symbol;
5
+ /**
6
+ * Symbol for defining custom setter logic for numeric index access
7
+ */
2
8
  declare const setAt: unique symbol;
3
9
  interface IndexingAt<Items = any> {
4
10
  [getAt](index: number): Items;
@@ -12,15 +18,35 @@ interface Accessor<T, Items> {
12
18
  declare abstract class AbstractGetAt<Items = any> {
13
19
  abstract [getAt](index: number): Items;
14
20
  }
21
+ /**
22
+ * Creates an indexable class with a base class and accessor object
23
+ * @param base - The base class to extend
24
+ * @param accessor - Object containing get/set methods for numeric index access
25
+ * @returns A class that supports numeric index access
26
+ */
15
27
  declare function Indexable<Items, Base extends abstract new (...args: any[]) => any>(base: Base, accessor: Accessor<InstanceType<Base>, Items>): new (...args: ConstructorParameters<Base>) => InstanceType<Base> & {
16
28
  [x: number]: Items;
17
29
  };
30
+ /**
31
+ * Creates an indexable class with only an accessor object (no base class)
32
+ * @param accessor - Object containing get/set methods for numeric index access
33
+ * @returns A class that supports numeric index access
34
+ */
18
35
  declare function Indexable<Items>(accessor: Accessor<any, Items>): new () => {
19
36
  [x: number]: Items;
20
37
  };
38
+ /**
39
+ * Creates an indexable class with a base class that has [getAt] method
40
+ * @param base - The base class that implements [getAt] method
41
+ * @returns A class that supports numeric index access using the base class's [getAt] method
42
+ */
21
43
  declare function Indexable<Base extends new (...args: any[]) => IndexingAt>(base: Base): new (...args: ConstructorParameters<Base>) => InstanceType<Base> & {
22
44
  [x: number]: AtReturnType<InstanceType<Base>>;
23
45
  };
46
+ /**
47
+ * Creates an abstract indexable base class
48
+ * @returns An abstract class that supports numeric index access
49
+ */
24
50
  declare function Indexable<Items>(): abstract new (...args: any[]) => AbstractGetAt & {
25
51
  [x: number]: Items;
26
52
  };
@@ -1,4 +1,10 @@
1
+ /**
2
+ * Symbol for defining custom getter logic for numeric index access
3
+ */
1
4
  const getAt = Symbol('getAt');
5
+ /**
6
+ * Symbol for defining custom setter logic for numeric index access
7
+ */
2
8
  const setAt = Symbol('setAt');
3
9
  function Indexable(base, accessor) {
4
10
  if (base && typeof base !== 'function') {
@@ -1 +1 @@
1
- {"version":3,"file":"indexable.esm.js","sources":["../src/indexable.ts"],"sourcesContent":["export const getAt = Symbol('getAt')\nexport const setAt = Symbol('setAt')\n\ninterface IndexingAt<Items = any> {\n\t[getAt](index: number): Items\n}\n\ninterface Accessor<T, Items> {\n\tget(this: T, index: number): Items\n\tset?(this: T, index: number, value: Items): void\n\tgetLength?(this: T): number\n\tsetLength?(this: T, value: number): void\n}\n\nabstract class AbstractGetAt<Items = any> {\n\tabstract [getAt](index: number): Items\n}\n\nexport function Indexable<Items, Base extends abstract new (...args: any[]) => any>(\n\tbase: Base,\n\taccessor: Accessor<InstanceType<Base>, Items>\n): new (\n\t...args: ConstructorParameters<Base>\n) => InstanceType<Base> & { [x: number]: Items }\n\nexport function Indexable<Items>(accessor: Accessor<any, Items>): new () => { [x: number]: Items }\n\nexport function Indexable<Base extends new (...args: any[]) => IndexingAt>(\n\tbase: Base\n): new (\n\t...args: ConstructorParameters<Base>\n) => InstanceType<Base> & { [x: number]: AtReturnType<InstanceType<Base>> }\n\nexport function Indexable<Items>(): abstract new (\n\t...args: any[]\n) => AbstractGetAt & { [x: number]: Items }\n\nexport function Indexable<Items, Base extends abstract new (...args: any[]) => any>(\n\tbase?: Base | Accessor<Base, Items>,\n\taccessor?: Accessor<Base, Items>\n) {\n\tif (base && typeof base !== 'function') {\n\t\taccessor = base as Accessor<Base, Items>\n\t\tbase = undefined\n\t}\n\tif (!base) {\n\t\t//@ts-expect-error\n\t\tbase = class {} as Base\n\t}\n\tif (!accessor) {\n\t\taccessor = {\n\t\t\tget(this: any, index: number) {\n\t\t\t\tif (typeof this[getAt] !== 'function') {\n\t\t\t\t\tthrow new Error('Indexable class must have an [getAt] method')\n\t\t\t\t}\n\t\t\t\treturn this[getAt](index)\n\t\t\t},\n\t\t\tset(this: any, index: number, value: Items) {\n\t\t\t\tif (typeof this[setAt] !== 'function') {\n\t\t\t\t\tthrow new Error('Indexable class has read-only numeric index access')\n\t\t\t\t}\n\t\t\t\tthis[setAt](index, value)\n\t\t\t},\n\t\t}\n\t}\n\n\tabstract class Indexable extends (base as Base) {\n\t\t[x: number]: Items\n\t}\n\n\tObject.setPrototypeOf(\n\t\tIndexable.prototype,\n\t\tnew Proxy((base as Base).prototype, {\n\t\t\t//@ts-expect-error\n\t\t\t[Symbol.toStringTag]: 'MutTs Indexable',\n\t\t\tget(target, prop, receiver) {\n\t\t\t\tif (prop in target) {\n\t\t\t\t\tconst getter = Object.getOwnPropertyDescriptor(target, prop)?.get\n\t\t\t\t\treturn getter ? getter.call(receiver) : target[prop]\n\t\t\t\t}\n\t\t\t\tif (typeof prop === 'string') {\n\t\t\t\t\tif (prop === 'length' && accessor.getLength) return accessor.getLength.call(receiver)\n\t\t\t\t\tconst numProp = Number(prop)\n\t\t\t\t\tif (!Number.isNaN(numProp)) {\n\t\t\t\t\t\treturn accessor.get!.call(receiver, numProp) as Items\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn undefined\n\t\t\t},\n\t\t\tset(target, prop, value, receiver) {\n\t\t\t\tif (prop in target) {\n\t\t\t\t\tconst setter = Object.getOwnPropertyDescriptor(target, prop)?.set\n\t\t\t\t\tif (setter) setter.call(receiver, value)\n\t\t\t\t\telse target[prop] = value\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t\tif (typeof prop === 'string') {\n\t\t\t\t\tif (prop === 'length' && accessor.setLength) {\n\t\t\t\t\t\taccessor.setLength.call(receiver, value)\n\t\t\t\t\t\treturn true\n\t\t\t\t\t}\n\t\t\t\t\tconst numProp = Number(prop)\n\t\t\t\t\tif (!Number.isNaN(numProp)) {\n\t\t\t\t\t\tif (!accessor.set) {\n\t\t\t\t\t\t\tthrow new Error('Indexable class has read-only numeric index access')\n\t\t\t\t\t\t}\n\t\t\t\t\t\taccessor.set!.call(receiver, numProp, value)\n\t\t\t\t\t\treturn true\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tObject.defineProperty(receiver, prop, {\n\t\t\t\t\tvalue,\n\t\t\t\t\twritable: true,\n\t\t\t\t\tenumerable: true,\n\t\t\t\t\tconfigurable: true,\n\t\t\t\t})\n\t\t\t\treturn true\n\t\t\t},\n\t\t})\n\t)\n\treturn Indexable\n}\n\ntype AtReturnType<T> = T extends { [getAt](index: number): infer R } ? R : never\n"],"names":[],"mappings":"MAAa,KAAK,GAAG,MAAM,CAAC,OAAO;MACtB,KAAK,GAAG,MAAM,CAAC,OAAO;AAoC7B,SAAU,SAAS,CACxB,IAAmC,EACnC,QAAgC,EAAA;AAEhC,IAAA,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE;QACvC,QAAQ,GAAG,IAA6B;QACxC,IAAI,GAAG,SAAS;IACjB;IACA,IAAI,CAAC,IAAI,EAAE;;AAEV,QAAA,IAAI,GAAG,MAAA;SAAgB;IACxB;IACA,IAAI,CAAC,QAAQ,EAAE;AACd,QAAA,QAAQ,GAAG;AACV,YAAA,GAAG,CAAY,KAAa,EAAA;gBAC3B,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,UAAU,EAAE;AACtC,oBAAA,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC;gBAC/D;AACA,gBAAA,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC;YAC1B,CAAC;YACD,GAAG,CAAY,KAAa,EAAE,KAAY,EAAA;gBACzC,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,UAAU,EAAE;AACtC,oBAAA,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC;gBACtE;gBACA,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC;YAC1B,CAAC;SACD;IACF;IAEA,MAAe,SAAU,SAAS,IAAa,CAAA;AAE9C;AAED,IAAA,MAAM,CAAC,cAAc,CACpB,SAAS,CAAC,SAAS,EACnB,IAAI,KAAK,CAAE,IAAa,CAAC,SAAS,EAAE;;AAEnC,QAAA,CAAC,MAAM,CAAC,W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BAC5C,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC;AACxC,oBAAA,OAAO,IAAI;gBACZ;AACA,gBAAA,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC;gBAC5B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE;AAC3B,oBAAA,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE;AAClB,wBAAA,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC;oBACtE;oBACA,QAAQ,CAAC,GAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,CAAC;AAC5C,oBAAA,OAAO,IAAI;gBACZ;YACD;AACA,YAAA,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,IAAI,EAAE;gBACrC,KAAK;AACL,gBAAA,QAAQ,EAAE,IAAI;AACd,gBAAA,UAAU,EAAE,IAAI;AAChB,gBAAA,YAAY,EAAE,IAAI;AAClB,aAAA,CAAC;AACF,YAAA,OAAO,IAAI;QACZ,CAAC;AACD,KAAA,CAAC,CACF;AACD,IAAA,OAAO,SAAS;AACjB;;;;"}
1
+ {"version":3,"file":"indexable.esm.js","sources":["../src/indexable.ts"],"sourcesContent":["/**\n * Symbol for defining custom getter logic for numeric index access\n */\nexport const getAt = Symbol('getAt')\n/**\n * Symbol for defining custom setter logic for numeric index access\n */\nexport const setAt = Symbol('setAt')\n\ninterface IndexingAt<Items = any> {\n\t[getAt](index: number): Items\n}\n\ninterface Accessor<T, Items> {\n\tget(this: T, index: number): Items\n\tset?(this: T, index: number, value: Items): void\n\tgetLength?(this: T): number\n\tsetLength?(this: T, value: number): void\n}\n\nabstract class AbstractGetAt<Items = any> {\n\tabstract [getAt](index: number): Items\n}\n\n/**\n * Creates an indexable class with a base class and accessor object\n * @param base - The base class to extend\n * @param accessor - Object containing get/set methods for numeric index access\n * @returns A class that supports numeric index access\n */\nexport function Indexable<Items, Base extends abstract new (...args: any[]) => any>(\n\tbase: Base,\n\taccessor: Accessor<InstanceType<Base>, Items>\n): new (\n\t...args: ConstructorParameters<Base>\n) => InstanceType<Base> & { [x: number]: Items }\n\n/**\n * Creates an indexable class with only an accessor object (no base class)\n * @param accessor - Object containing get/set methods for numeric index access\n * @returns A class that supports numeric index access\n */\nexport function Indexable<Items>(accessor: Accessor<any, Items>): new () => { [x: number]: Items }\n\n/**\n * Creates an indexable class with a base class that has [getAt] method\n * @param base - The base class that implements [getAt] method\n * @returns A class that supports numeric index access using the base class's [getAt] method\n */\nexport function Indexable<Base extends new (...args: any[]) => IndexingAt>(\n\tbase: Base\n): new (\n\t...args: ConstructorParameters<Base>\n) => InstanceType<Base> & { [x: number]: AtReturnType<InstanceType<Base>> }\n\n/**\n * Creates an abstract indexable base class\n * @returns An abstract class that supports numeric index access\n */\nexport function Indexable<Items>(): abstract new (\n\t...args: any[]\n) => AbstractGetAt & { [x: number]: Items }\n\nexport function Indexable<Items, Base extends abstract new (...args: any[]) => any>(\n\tbase?: Base | Accessor<Base, Items>,\n\taccessor?: Accessor<Base, Items>\n) {\n\tif (base && typeof base !== 'function') {\n\t\taccessor = base as Accessor<Base, Items>\n\t\tbase = undefined\n\t}\n\tif (!base) {\n\t\t//@ts-expect-error\n\t\tbase = class {} as Base\n\t}\n\tif (!accessor) {\n\t\taccessor = {\n\t\t\tget(this: any, index: number) {\n\t\t\t\tif (typeof this[getAt] !== 'function') {\n\t\t\t\t\tthrow new Error('Indexable class must have an [getAt] method')\n\t\t\t\t}\n\t\t\t\treturn this[getAt](index)\n\t\t\t},\n\t\t\tset(this: any, index: number, value: Items) {\n\t\t\t\tif (typeof this[setAt] !== 'function') {\n\t\t\t\t\tthrow new Error('Indexable class has read-only numeric index access')\n\t\t\t\t}\n\t\t\t\tthis[setAt](index, value)\n\t\t\t},\n\t\t}\n\t}\n\n\tabstract class Indexable extends (base as Base) {\n\t\t[x: number]: Items\n\t}\n\n\tObject.setPrototypeOf(\n\t\tIndexable.prototype,\n\t\tnew Proxy((base as Base).prototype, {\n\t\t\t//@ts-expect-error\n\t\t\t[Symbol.toStringTag]: 'MutTs Indexable',\n\t\t\tget(target, prop, receiver) {\n\t\t\t\tif (prop in target) {\n\t\t\t\t\tconst getter = Object.getOwnPropertyDescriptor(target, prop)?.get\n\t\t\t\t\treturn getter ? getter.call(receiver) : target[prop]\n\t\t\t\t}\n\t\t\t\tif (typeof prop === 'string') {\n\t\t\t\t\tif (prop === 'length' && accessor.getLength) return accessor.getLength.call(receiver)\n\t\t\t\t\tconst numProp = Number(prop)\n\t\t\t\t\tif (!Number.isNaN(numProp)) {\n\t\t\t\t\t\treturn accessor.get!.call(receiver, numProp) as Items\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn undefined\n\t\t\t},\n\t\t\tset(target, prop, value, receiver) {\n\t\t\t\tif (prop in target) {\n\t\t\t\t\tconst setter = Object.getOwnPropertyDescriptor(target, prop)?.set\n\t\t\t\t\tif (setter) setter.call(receiver, value)\n\t\t\t\t\telse target[prop] = value\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t\tif (typeof prop === 'string') {\n\t\t\t\t\tif (prop === 'length' && accessor.setLength) {\n\t\t\t\t\t\taccessor.setLength.call(receiver, value)\n\t\t\t\t\t\treturn true\n\t\t\t\t\t}\n\t\t\t\t\tconst numProp = Number(prop)\n\t\t\t\t\tif (!Number.isNaN(numProp)) {\n\t\t\t\t\t\tif (!accessor.set) {\n\t\t\t\t\t\t\tthrow new Error('Indexable class has read-only numeric index access')\n\t\t\t\t\t\t}\n\t\t\t\t\t\taccessor.set!.call(receiver, numProp, value)\n\t\t\t\t\t\treturn true\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tObject.defineProperty(receiver, prop, {\n\t\t\t\t\tvalue,\n\t\t\t\t\twritable: true,\n\t\t\t\t\tenumerable: true,\n\t\t\t\t\tconfigurable: true,\n\t\t\t\t})\n\t\t\t\treturn true\n\t\t\t},\n\t\t})\n\t)\n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gBAAA,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC;gBAC5B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE;AAC3B,oBAAA,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE;AAClB,wBAAA,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC;oBACtE;oBACA,QAAQ,CAAC,GAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,CAAC;AAC5C,oBAAA,OAAO,IAAI;gBACZ;YACD;AACA,YAAA,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,IAAI,EAAE;gBACrC,KAAK;AACL,gBAAA,QAAQ,EAAE,IAAI;AACd,gBAAA,UAAU,EAAE,IAAI;AAChB,gBAAA,YAAY,EAAE,IAAI;AAClB,aAAA,CAAC;AACF,YAAA,OAAO,IAAI;QACZ,CAAC;AACD,KAAA,CAAC,CACF;AACD,IAAA,OAAO,SAAS;AACjB;;;;"}
package/dist/indexable.js CHANGED
@@ -1,6 +1,12 @@
1
1
  'use strict';
2
2
 
3
+ /**
4
+ * Symbol for defining custom getter logic for numeric index access
5
+ */
3
6
  const getAt = Symbol('getAt');
7
+ /**
8
+ * Symbol for defining custom setter logic for numeric index access
9
+ */
4
10
  const setAt = Symbol('setAt');
5
11
  function Indexable(base, accessor) {
6
12
  if (base && typeof base !== 'function') {
@@ -1 +1 @@
1
- {"version":3,"file":"indexable.js","sources":["../src/indexable.ts"],"sourcesContent":["export const getAt = Symbol('getAt')\nexport const setAt = Symbol('setAt')\n\ninterface IndexingAt<Items = any> {\n\t[getAt](index: number): Items\n}\n\ninterface Accessor<T, Items> {\n\tget(this: T, index: number): Items\n\tset?(this: T, index: number, value: Items): void\n\tgetLength?(this: T): number\n\tsetLength?(this: T, value: number): void\n}\n\nabstract class AbstractGetAt<Items = any> {\n\tabstract [getAt](index: number): Items\n}\n\nexport function Indexable<Items, Base extends abstract new (...args: any[]) => any>(\n\tbase: Base,\n\taccessor: Accessor<InstanceType<Base>, Items>\n): new (\n\t...args: ConstructorParameters<Base>\n) => InstanceType<Base> & { [x: number]: Items }\n\nexport function Indexable<Items>(accessor: Accessor<any, Items>): new () => { [x: number]: Items }\n\nexport function Indexable<Base extends new (...args: any[]) => IndexingAt>(\n\tbase: Base\n): new (\n\t...args: ConstructorParameters<Base>\n) => InstanceType<Base> & { [x: number]: AtReturnType<InstanceType<Base>> }\n\nexport function Indexable<Items>(): abstract new (\n\t...args: any[]\n) => AbstractGetAt & { [x: number]: Items }\n\nexport function Indexable<Items, Base extends abstract new (...args: any[]) => any>(\n\tbase?: Base | Accessor<Base, Items>,\n\taccessor?: Accessor<Base, Items>\n) {\n\tif (base && typeof base !== 'function') {\n\t\taccessor = base as Accessor<Base, Items>\n\t\tbase = undefined\n\t}\n\tif (!base) {\n\t\t//@ts-expect-error\n\t\tbase = class {} as Base\n\t}\n\tif (!accessor) {\n\t\taccessor = {\n\t\t\tget(this: any, index: number) {\n\t\t\t\tif (typeof this[getAt] !== 'function') {\n\t\t\t\t\tthrow new Error('Indexable class must have an [getAt] method')\n\t\t\t\t}\n\t\t\t\treturn this[getAt](index)\n\t\t\t},\n\t\t\tset(this: any, index: number, value: Items) {\n\t\t\t\tif (typeof this[setAt] !== 'function') {\n\t\t\t\t\tthrow new Error('Indexable class has read-only numeric index access')\n\t\t\t\t}\n\t\t\t\tthis[setAt](index, value)\n\t\t\t},\n\t\t}\n\t}\n\n\tabstract class Indexable extends (base as Base) {\n\t\t[x: number]: Items\n\t}\n\n\tObject.setPrototypeOf(\n\t\tIndexable.prototype,\n\t\tnew Proxy((base as Base).prototype, {\n\t\t\t//@ts-expect-error\n\t\t\t[Symbol.toStringTag]: 'MutTs Indexable',\n\t\t\tget(target, prop, receiver) {\n\t\t\t\tif (prop in target) {\n\t\t\t\t\tconst getter = Object.getOwnPropertyDescriptor(target, prop)?.get\n\t\t\t\t\treturn getter ? getter.call(receiver) : target[prop]\n\t\t\t\t}\n\t\t\t\tif (typeof prop === 'string') {\n\t\t\t\t\tif (prop === 'length' && accessor.getLength) return accessor.getLength.call(receiver)\n\t\t\t\t\tconst numProp = Number(prop)\n\t\t\t\t\tif (!Number.isNaN(numProp)) {\n\t\t\t\t\t\treturn accessor.get!.call(receiver, numProp) as Items\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn undefined\n\t\t\t},\n\t\t\tset(target, prop, value, receiver) {\n\t\t\t\tif (prop in target) {\n\t\t\t\t\tconst setter = Object.getOwnPropertyDescriptor(target, prop)?.set\n\t\t\t\t\tif (setter) setter.call(receiver, value)\n\t\t\t\t\telse target[prop] = value\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t\tif (typeof prop === 'string') {\n\t\t\t\t\tif (prop === 'length' && accessor.setLength) {\n\t\t\t\t\t\taccessor.setLength.call(receiver, value)\n\t\t\t\t\t\treturn true\n\t\t\t\t\t}\n\t\t\t\t\tconst numProp = Number(prop)\n\t\t\t\t\tif (!Number.isNaN(numProp)) {\n\t\t\t\t\t\tif (!accessor.set) {\n\t\t\t\t\t\t\tthrow new Error('Indexable class has read-only numeric index access')\n\t\t\t\t\t\t}\n\t\t\t\t\t\taccessor.set!.call(receiver, numProp, value)\n\t\t\t\t\t\treturn true\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tObject.defineProperty(receiver, prop, {\n\t\t\t\t\tvalue,\n\t\t\t\t\twritable: true,\n\t\t\t\t\tenumerable: true,\n\t\t\t\t\tconfigurable: true,\n\t\t\t\t})\n\t\t\t\treturn true\n\t\t\t},\n\t\t})\n\t)\n\treturn Indexable\n}\n\ntype AtReturnType<T> = T extends { [getAt](index: number): infer R } ? R : never\n"],"names":[],"mappings":";;MAAa,KAAK,GAAG,MAAM,CAAC,OAAO;MACtB,KAAK,GAAG,MAAM,CAAC,OAAO;AAoC7B,SAAU,SAAS,CACxB,IAAmC,EACnC,QAAgC,EAAA;AAEhC,IAAA,IAAI,IAAI,IAAI,OAAO,IA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QAAQ,EAAE,OAAO,EAAE,KAAK,CAAC;AAC5C,oBAAA,OAAO,IAAI;gBACZ;YACD;AACA,YAAA,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,IAAI,EAAE;gBACrC,KAAK;AACL,gBAAA,QAAQ,EAAE,IAAI;AACd,gBAAA,UAAU,EAAE,IAAI;AAChB,gBAAA,YAAY,EAAE,IAAI;AAClB,aAAA,CAAC;AACF,YAAA,OAAO,IAAI;QACZ,CAAC;AACD,KAAA,CAAC,CACF;AACD,IAAA,OAAO,SAAS;AACjB;;;;;;"}
1
+ {"version":3,"file":"indexable.js","sources":["../src/indexable.ts"],"sourcesContent":["/**\n * Symbol for defining custom getter logic for numeric index access\n */\nexport const getAt = Symbol('getAt')\n/**\n * Symbol for defining custom setter logic for numeric index access\n */\nexport const setAt = Symbol('setAt')\n\ninterface IndexingAt<Items = any> {\n\t[getAt](index: number): Items\n}\n\ninterface Accessor<T, Items> {\n\tget(this: T, index: number): Items\n\tset?(this: T, index: number, value: Items): void\n\tgetLength?(this: T): number\n\tsetLength?(this: T, value: number): void\n}\n\nabstract class AbstractGetAt<Items = any> {\n\tabstract [getAt](index: number): Items\n}\n\n/**\n * Creates an indexable class with a base class and accessor object\n * @param base - The base class to extend\n * @param accessor - Object containing get/set methods for numeric index access\n * @returns A class that supports numeric index access\n */\nexport function Indexable<Items, Base extends abstract new (...args: any[]) => any>(\n\tbase: Base,\n\taccessor: Accessor<InstanceType<Base>, Items>\n): new (\n\t...args: ConstructorParameters<Base>\n) => InstanceType<Base> & { [x: number]: Items }\n\n/**\n * Creates an indexable class with only an accessor object (no base class)\n * @param accessor - Object containing get/set methods for numeric index access\n * @returns A class that supports numeric index access\n */\nexport function Indexable<Items>(accessor: Accessor<any, Items>): new () => { [x: number]: Items }\n\n/**\n * Creates an indexable class with a base class that has [getAt] method\n * @param base - The base class that implements [getAt] method\n * @returns A class that supports numeric index access using the base class's [getAt] method\n */\nexport function Indexable<Base extends new (...args: any[]) => IndexingAt>(\n\tbase: Base\n): new (\n\t...args: ConstructorParameters<Base>\n) => InstanceType<Base> & { [x: number]: AtReturnType<InstanceType<Base>> }\n\n/**\n * Creates an abstract indexable base class\n * @returns An abstract class that supports numeric index access\n */\nexport function Indexable<Items>(): abstract new (\n\t...args: any[]\n) => AbstractGetAt & { [x: number]: Items }\n\nexport function Indexable<Items, Base extends abstract new (...args: any[]) => any>(\n\tbase?: Base | Accessor<Base, Items>,\n\taccessor?: Accessor<Base, Items>\n) {\n\tif (base && typeof base !== 'function') {\n\t\taccessor = base as Accessor<Base, Items>\n\t\tbase = undefined\n\t}\n\tif (!base) {\n\t\t//@ts-expect-error\n\t\tbase = class {} as Base\n\t}\n\tif (!accessor) {\n\t\taccessor = {\n\t\t\tget(this: any, index: number) {\n\t\t\t\tif (typeof this[getAt] !== 'function') {\n\t\t\t\t\tthrow new Error('Indexable class must have an [getAt] method')\n\t\t\t\t}\n\t\t\t\treturn this[getAt](index)\n\t\t\t},\n\t\t\tset(this: any, index: number, value: Items) {\n\t\t\t\tif (typeof this[setAt] !== 'function') {\n\t\t\t\t\tthrow new Error('Indexable class has read-only numeric index access')\n\t\t\t\t}\n\t\t\t\tthis[setAt](index, value)\n\t\t\t},\n\t\t}\n\t}\n\n\tabstract class Indexable extends (base as Base) {\n\t\t[x: number]: Items\n\t}\n\n\tObject.setPrototypeOf(\n\t\tIndexable.prototype,\n\t\tnew Proxy((base as Base).prototype, {\n\t\t\t//@ts-expect-error\n\t\t\t[Symbol.toStringTag]: 'MutTs Indexable',\n\t\t\tget(target, prop, receiver) {\n\t\t\t\tif (prop in target) {\n\t\t\t\t\tconst getter = Object.getOwnPropertyDescriptor(target, prop)?.get\n\t\t\t\t\treturn getter ? getter.call(receiver) : target[prop]\n\t\t\t\t}\n\t\t\t\tif (typeof prop === 'string') {\n\t\t\t\t\tif (prop === 'length' && accessor.getLength) return accessor.getLength.call(receiver)\n\t\t\t\t\tconst numProp = Number(prop)\n\t\t\t\t\tif (!Number.isNaN(numProp)) {\n\t\t\t\t\t\treturn accessor.get!.call(receiver, numProp) as Items\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn undefined\n\t\t\t},\n\t\t\tset(target, prop, value, receiver) {\n\t\t\t\tif (prop in target) {\n\t\t\t\t\tconst setter = Object.getOwnPropertyDescriptor(target, prop)?.set\n\t\t\t\t\tif (setter) setter.call(receiver, value)\n\t\t\t\t\telse target[prop] = value\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t\tif (typeof prop === 'string') {\n\t\t\t\t\tif (prop === 'length' && accessor.setLength) {\n\t\t\t\t\t\taccessor.setLength.call(receiver, value)\n\t\t\t\t\t\treturn true\n\t\t\t\t\t}\n\t\t\t\t\tconst numProp = Number(prop)\n\t\t\t\t\tif (!Number.isNaN(numProp)) {\n\t\t\t\t\t\tif (!accessor.set) {\n\t\t\t\t\t\t\tthrow new Error('Indexable class has read-only numeric index access')\n\t\t\t\t\t\t}\n\t\t\t\t\t\taccessor.set!.call(receiver, numProp, value)\n\t\t\t\t\t\treturn true\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tObject.defineProperty(receiver, prop, {\n\t\t\t\t\tvalue,\n\t\t\t\t\twritable: true,\n\t\t\t\t\tenumerable: true,\n\t\t\t\t\tconfigurable: true,\n\t\t\t\t})\n\t\t\t\treturn true\n\t\t\t},\n\t\t})\n\t)\n\treturn Indexable\n}\n\ntype AtReturnType<T> = T extends { [getAt](index: number): infer R } ? R : never\n"],"names":[],"mappings":";;AAAA;;AAEG;MACU,KAAK,GAAG,MAAM,CAAC,OAAO;AACnC;;AAEG;MACU,KAAK,GAAG,MAAM,CAAC,OAAO;AAwD7B,SAAU,SAAS,CACxB,IAAmC,EACnC,QAAgC,EAAA;AAEhC,IAAA,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE;QACvC,QAAQ,GAAG,IAA6B;QACxC,IAAI,GAAG,SAAS;IACjB;IACA,IAAI,CAAC,IAAI,EAAE;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