@yhwh-script/event-bux 1.0.6 → 1.0.7

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 (2) hide show
  1. package/index.js +7 -4
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -2,7 +2,7 @@ export const name = "eventbux"; // The module name, can be made globally availab
2
2
  const listeners = new WeakMap(); // WeakMap to store listeners per object. Keep it private unless you know what you do.
3
3
  // Should auto-cleanup listeners when object is GC'd (TODO Test!)
4
4
  // This module implements EventTarget.
5
- export const addEventListener = function (type, listener, context = undefined) { // (TODO check integration into options)
5
+ export function addEventListener(type, listener, context = undefined) { // (TODO check integration into options)
6
6
  if (context && typeof context === 'object') { // context is well defined, should be a WebComponent
7
7
  if (!listeners.has(context)) { // context is yet unknown to the listeners
8
8
  listeners.set(context, new Map()); // will be stored here
@@ -14,13 +14,13 @@ export const addEventListener = function (type, listener, context = undefined) {
14
14
  contextListeners.get(type).push(listener);
15
15
  } else { // default
16
16
  if (context) { // illegal context
17
- throw new Error("Syntax error.")
17
+ throw new Error("Syntax error.");
18
18
  }
19
19
  window.addEventListener(type, listener);
20
20
  }
21
21
  }
22
22
 
23
- export const removeEventListener = function (type, listener, context = undefined) {
23
+ export function removeEventListener(type, listener, context = undefined) {
24
24
  if (context && typeof context === 'object') {
25
25
  const contextListeners = listeners.get(context);
26
26
  if (contextListeners && contextListeners.has(type)) {
@@ -35,7 +35,10 @@ export const removeEventListener = function (type, listener, context = undefined
35
35
  }
36
36
  }
37
37
 
38
- export const dispatchEvent = function (event, context = undefined) { // TODO check if context == event.target, if yes, remove context? What if CustomEvent is used?
38
+ export function dispatchEvent(event, context = undefined) { // TODO check if context == event.target, if yes, remove context? What if CustomEvent is used?
39
+ if (!context) { // observe!
40
+ context = event.target;
41
+ }
39
42
  if (context && listeners.has(context)) {
40
43
  const contextListeners = listeners.get(context);
41
44
  if (contextListeners.has(event.type)) { // Call context-specific listeners
package/package.json CHANGED
@@ -22,5 +22,5 @@
22
22
  "url": "git+https://github.com/yhwh-script/event-bux.git"
23
23
  },
24
24
  "type": "module",
25
- "version": "1.0.6"
25
+ "version": "1.0.7"
26
26
  }