@d1g1tal/subscribr 4.0.3 → 4.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/subscribr.js.map +3 -3
- package/package.json +12 -13
package/dist/subscribr.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../node_modules/.pnpm/@d1g1tal+collections@2.
|
|
4
|
-
"sourcesContent": ["/** A {@link Map} that can contain multiple, unique, values for the same key. */\nexport class SetMultiMap<K, V> extends Map<K, Set<V>>{\n\t/**\n\t * Adds a new element with a specified key and value to the SetMultiMap.\n\t * If an element with the same key already exists, the value will be added to the underlying {@link Set}.\n\t * If the value already exists in the {@link Set}, it will not be added again.\n\t *\n\t * @param
|
|
5
|
-
"mappings": "AACO,IAAMA,EAAN,cAAgC,GAAc,CAW3C,IAAIC,EAAQC,EAA6B,CACjD,aAAM,IAAID,GAAM,MAAM,IAAIA,CAAG,GAAK,IAAI,KAAO,IAAIC,CAAK,CAAC,EAEhD,IACR,CASA,SAASD,EAAQC,EAAmB,CACnC,IAAMC,EAAS,MAAM,IAAIF,CAAG,EAE5B,OAAOE,EAASA,EAAO,IAAID,CAAK,EAAI,EACrC,
|
|
3
|
+
"sources": ["../node_modules/.pnpm/@d1g1tal+collections@2.1.0_typescript@5.9.3/node_modules/@d1g1tal/collections/src/set-multi-map.ts", "../src/context-event-handler.ts", "../src/subscription.ts", "../src/subscribr.ts"],
|
|
4
|
+
"sourcesContent": ["/** A {@link Map} that can contain multiple, unique, values for the same key. */\nexport class SetMultiMap<K, V> extends Map<K, Set<V>>{\n\t/**\n\t * Adds a new element with a specified key and value to the SetMultiMap.\n\t * If an element with the same key already exists, the value will be added to the underlying {@link Set}.\n\t * If the value already exists in the {@link Set}, it will not be added again.\n\t *\n\t * @param key The key to set.\n\t * @param value The value to add to the SetMultiMap\n\t * @returns The SetMultiMap with the updated key and value.\n\t */\n\t// @ts-expect-error I am overriding the set method from the Map class\n\toverride set(key: K, value: V): SetMultiMap<K, V> {\n\t\tsuper.set(key, (super.get(key) ?? new Set()).add(value));\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Checks if a specific key has a specific value.\n\t *\n\t * @param key The key to check.\n\t * @param value The value to check.\n\t * @returns True if the key has the value, false otherwise.\n\t */\n\thasValue(key: K, value: V): boolean {\n\t\tconst values = super.get(key);\n\n\t\treturn values ? values.has(value) : false;\n\t}\n\n\t/**\n\t * Finds a specific value for a specific key using an iterator function.\n\t * @param key The key to find the value for.\n\t * @param iterator The iterator function to use to find the value.\n\t * @returns The value for the specified key\n\t */\n\tfind(key: K, iterator: (value: V) => boolean): V | undefined {\n\t\tconst values = this.get(key);\n\n\t\tif (values !== undefined) {\n\t\t\treturn Array.from(values).find(iterator);\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Removes a specific value from a specific key.\n\t * @param key The key to remove the value from.\n\t * @param value The value to remove.\n\t * @returns True if the value was removed, false otherwise.\n\t */\n\tdeleteValue(key: K, value: V | undefined): boolean {\n\t\tif (value === undefined) { return this.delete(key) }\n\n\t\tconst values = super.get(key);\n\t\tif (values) {\n\t\t\tconst deleted = values.delete(value);\n\n\t\t\tif (values.size === 0) {\n\t\t\t\tsuper.delete(key);\n\t\t\t}\n\n\t\t\treturn deleted;\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t/**\n\t * The string tag of the SetMultiMap.\n\t * @returns The string tag of the SetMultiMap.\n\t */\n\toverride get [Symbol.toStringTag](): string {\n\t\treturn 'SetMultiMap';\n\t}\n}", "import type { ContextEventListener } from './@types';\n\n/** A wrapper for an event handler that binds a context to the event handler. */\nexport class ContextEventHandler {\n\tprivate readonly context: unknown;\n\tprivate readonly eventListener: ContextEventListener;\n\n\t/**\n\t * @param context The context to bind to the event handler.\n\t * @param eventListener The event handler to call when the event is published.\n\t */\n\tconstructor(context: unknown, eventListener: ContextEventListener) {\n\t\tthis.context = context;\n\t\tthis.eventListener = eventListener;\n\t}\n\n\t/**\n\t * Call the event handler for the provided event.\n\t *\n\t * @param event The event to handle\n\t * @param data The value to be passed to the event handler as a parameter.\n\t */\n\thandle(event: Event, data?: unknown): void {\n\t\tthis.eventListener.call(this.context, event, data);\n\t}\n\n\t/**\n\t * A String value that is used in the creation of the default string\n\t * description of an object. Called by the built-in method {@link Object.prototype.toString}.\n\t *\n\t * @returns The default string description of this object.\n\t */\n\tget [Symbol.toStringTag](): string {\n\t\treturn 'ContextEventHandler';\n\t}\n}", "import type { ContextEventHandler } from './context-event-handler';\n\n/** Represents a subscription to an event. */\nexport class Subscription {\n\tprivate readonly _eventName: string;\n\tprivate readonly _contextEventHandler: ContextEventHandler;\n\n\t/**\n\t * @param eventName The event name.\n\t * @param contextEventHandler The context event handler.\n\t */\n\tconstructor(eventName: string, contextEventHandler: ContextEventHandler) {\n\t\tthis._eventName = eventName;\n\t\tthis._contextEventHandler = contextEventHandler;\n\t}\n\n\t/**\n\t * Gets the event name for the subscription.\n\t *\n\t * @returns The event name.\n\t */\n\tget eventName(): string {\n\t\treturn this._eventName;\n\t}\n\n\t/**\n\t * Gets the context event handler.\n\t *\n\t * @returns The context event handler\n\t */\n\tget contextEventHandler(): ContextEventHandler {\n\t\treturn this._contextEventHandler;\n\t}\n\n\t/**\n\t * A String value that is used in the creation of the default string\n\t * description of an object. Called by the built-in method {@link Object.prototype.toString}.\n\t *\n\t * @returns The default string description of this object.\n\t */\n\tget [Symbol.toStringTag](): string {\n\t\treturn 'Subscription';\n\t}\n}", "import { SetMultiMap } from '@d1g1tal/collections/src';\nimport { ContextEventHandler } from './context-event-handler';\nimport { Subscription } from './subscription';\nimport type { ContextEventListener } from './@types';\n\n/** A class that allows objects to subscribe to events and be notified when the event is published. */\nexport class Subscribr {\n\tprivate readonly subscribers: SetMultiMap<string, ContextEventHandler>;\n\n\tconstructor() {\n\t\tthis.subscribers = new SetMultiMap();\n\t}\n\n\t/**\n\t * Subscribe to an event\n\t *\n\t * @param eventName The event name to subscribe to.\n\t * @param eventHandler The event handler to call when the event is published.\n\t * @param context The context to bind to the event handler.\n\t * @returns An object used to check if the subscription still exists and to unsubscribe from the event.\n\t */\n\tsubscribe(eventName: string, eventHandler: ContextEventListener, context: unknown = eventHandler): Subscription {\n\t\tconst contextEventHandler = new ContextEventHandler(context, eventHandler);\n\t\tthis.subscribers.set(eventName, contextEventHandler);\n\n\t\treturn new Subscription(eventName, contextEventHandler);\n\t}\n\n\t/**\n\t * Unsubscribe from the event\n\t *\n\t * @param subscription The subscription to unsubscribe.\n\t * @returns true if eventListener has been removed successfully. false if the value is not found or if the value is not an object.\n\t */\n\tunsubscribe({ eventName, contextEventHandler }: Subscription): boolean {\n\t\tconst contextEventHandlers = this.subscribers.get(eventName) ?? new Set();\n\t\tconst removed = contextEventHandlers.delete(contextEventHandler);\n\n\t\tif (removed && contextEventHandlers.size === 0) {\tthis.subscribers.delete(eventName) }\n\n\t\treturn removed;\n\t}\n\n\t/**\n\t * Publish an event\n\t *\n\t * @template T\n\t * @param eventName The name of the event.\n\t * @param event The event to be handled.\n\t * @param data The value to be passed to the event handler as a parameter.\n\t */\n\tpublish<T>(eventName: string, event: Event = new CustomEvent(eventName), data?: T): void {\n\t\tthis.subscribers.get(eventName)?.forEach((contextEventHandler: ContextEventHandler) => contextEventHandler.handle(event, data));\n\t}\n\n\t/**\n\t * Check if the event and handler are subscribed.\n\t *\n\t * @param subscription The subscription object.\n\t * @returns true if the event name and handler are subscribed, false otherwise.\n\t */\n\tisSubscribed({ eventName, contextEventHandler }: Subscription): boolean {\n\t\treturn this.subscribers.get(eventName)?.has(contextEventHandler) ?? false;\n\t}\n\n\t/**\n\t * A String value that is used in the creation of the default string\n\t * description of an object. Called by the built-in method {@link Object.prototype.toString}.\n\t *\n\t * @returns The default string description of this object.\n\t */\n\tget [Symbol.toStringTag](): string {\n\t\treturn 'Subscribr';\n\t}\n}"],
|
|
5
|
+
"mappings": "AACO,IAAMA,E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,KAAgB,CACL,YAEjB,aAAc,CACb,KAAK,YAAc,IAAIC,CACxB,CAUA,UAAUC,EAAmBC,EAAoCC,EAAmBD,EAA4B,CAC/G,IAAME,EAAsB,IAAIC,EAAoBF,EAASD,CAAY,EACzE,YAAK,YAAY,IAAID,EAAWG,CAAmB,EAE5C,IAAIE,EAAaL,EAAWG,CAAmB,CACvD,CAQA,YAAY,CAAE,UAAAH,EAAW,oBAAAG,CAAoB,EAA0B,CACtE,IAAMG,EAAuB,KAAK,YAAY,IAAIN,CAAS,GAAK,IAAI,IAC9DO,EAAUD,EAAqB,OAAOH,CAAmB,EAE/D,OAAII,GAAWD,EAAqB,OAAS,GAAK,KAAK,YAAY,OAAON,CAAS,EAE5EO,CACR,CAUA,QAAWP,EAAmBQ,EAAe,IAAI,YAAYR,CAAS,EAAGS,EAAgB,CACxF,KAAK,YAAY,IAAIT,CAAS,GAAG,QAASG,GAA6CA,EAAoB,OAAOK,EAAOC,CAAI,CAAC,CAC/H,CAQA,aAAa,CAAE,UAAAT,EAAW,oBAAAG,CAAoB,EAA0B,CACvE,OAAO,KAAK,YAAY,IAAIH,CAAS,GAAG,IAAIG,CAAmB,GAAK,EACrE,CAQA,IAAK,OAAO,WAAW,GAAY,CAClC,MAAO,WACR,CACD",
|
|
6
6
|
"names": ["SetMultiMap", "key", "value", "values", "iterator", "deleted", "ContextEventHandler", "context", "eventListener", "event", "data", "Subscription", "eventName", "contextEventHandler", "Subscribr", "SetMultiMap", "eventName", "eventHandler", "context", "contextEventHandler", "ContextEventHandler", "Subscription", "contextEventHandlers", "removed", "event", "data"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d1g1tal/subscribr",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.4",
|
|
4
4
|
"description": "JavaScript Publish/Subscribe Library",
|
|
5
5
|
"author": "Jason DiMeo",
|
|
6
6
|
"license": "ISC",
|
|
@@ -36,34 +36,33 @@
|
|
|
36
36
|
"url": "git+https://github.com/D1g1talEntr0py/subscribr.git"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@d1g1tal/collections": "^2.0
|
|
39
|
+
"@d1g1tal/collections": "^2.1.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@d1g1tal/chrysalis": "^2.5.0",
|
|
43
|
-
"@eslint/compat": "^1.
|
|
44
|
-
"@eslint/js": "^9.
|
|
45
|
-
"@types/node": "^24.
|
|
46
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
47
|
-
"@typescript-eslint/parser": "^8.
|
|
43
|
+
"@eslint/compat": "^1.4.0",
|
|
44
|
+
"@eslint/js": "^9.37.0",
|
|
45
|
+
"@types/node": "^24.7.1",
|
|
46
|
+
"@typescript-eslint/eslint-plugin": "^8.46.0",
|
|
47
|
+
"@typescript-eslint/parser": "^8.46.0",
|
|
48
48
|
"@vitest/coverage-v8": "^3.2.4",
|
|
49
|
-
"eslint": "^9.
|
|
49
|
+
"eslint": "^9.37.0",
|
|
50
50
|
"eslint-plugin-compat": "^6.0.2",
|
|
51
|
-
"eslint-plugin-jsdoc": "^
|
|
52
|
-
"
|
|
51
|
+
"eslint-plugin-jsdoc": "^61.1.0",
|
|
52
|
+
"tsbuild": "link:../tsbuild",
|
|
53
|
+
"typescript-eslint": "^8.46.0",
|
|
53
54
|
"vitest": "^3.2.4"
|
|
54
55
|
},
|
|
55
56
|
"peerDependencies": {
|
|
56
57
|
"typescript": "^5.0.0"
|
|
57
58
|
},
|
|
58
|
-
"engines": {
|
|
59
|
-
"node": ">=20.15.1"
|
|
60
|
-
},
|
|
61
59
|
"browserslist": [
|
|
62
60
|
"defaults and fully supports es6-module",
|
|
63
61
|
"node >= 20.15.1"
|
|
64
62
|
],
|
|
65
63
|
"scripts": {
|
|
66
64
|
"build": "tsbuild",
|
|
65
|
+
"build:minify": "tsbuild --minify --force",
|
|
67
66
|
"build:watch": "tsbuild --watch",
|
|
68
67
|
"type-check": "tsbuild --typeCheck",
|
|
69
68
|
"lint": "eslint ./src",
|