@domql/event 2.31.0 → 2.31.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/on.js CHANGED
@@ -32,9 +32,10 @@ const getOnOrPropsEvent = (param, element) => {
32
32
  const onPropEvent = (_b = element.props) == null ? void 0 : _b["on" + param.slice(0, 1).toUpperCase() + param.slice(1)];
33
33
  return onEvent || onPropEvent;
34
34
  };
35
- const applyEvent = (param, element, state, context, options) => {
36
- if (!param.call) element.warn(`Event is not executable: ${param}`);
37
- return param.call(
35
+ const applyEvent = (fnValue, element, state, context, options) => {
36
+ if ((0, import_utils.isString)(fnValue)) fnValue = import_utils.getContextFunction.call(element, fnValue);
37
+ if (!fnValue.call) element.warn(`Event is not executable: ${fnValue}`);
38
+ return fnValue.call(
38
39
  element,
39
40
  element,
40
41
  state || element.state,
@@ -49,9 +50,10 @@ const triggerEventOn = async (param, element, options) => {
49
50
  return await applyEvent(appliedFunction, element, state, context, options);
50
51
  }
51
52
  };
52
- const applyEventUpdate = (param, updatedObj, element, state, context, options) => {
53
- if (!param.call) element.warn(`Event is not executable: ${param}`);
54
- return param.call(
53
+ const applyEventUpdate = (fnValue, updatedObj, element, state, context, options) => {
54
+ if ((0, import_utils.isString)(fnValue)) fnValue = import_utils.getContextFunction.call(element, fnValue);
55
+ if (!fnValue.call) element.warn(`Event is not executable: ${fnValue}`);
56
+ return fnValue.call(
55
57
  element,
56
58
  updatedObj,
57
59
  element,
@@ -79,18 +81,14 @@ const applyEventsOnNode = (element, options) => {
79
81
  for (const param in on) {
80
82
  if (param === "init" || param === "beforeClassAssign" || param === "render" || param === "renderRouter" || param === "attachNode" || param === "stateInit" || param === "stateCreated" || param === "beforeStateUpdate" || param === "stateUpdate" || param === "beforeUpdate" || param === "done" || param === "create" || param === "complete" || param === "frame" || param === "update")
81
83
  continue;
82
- const appliedFunction = getOnOrPropsEvent(param, element);
83
- if ((0, import_utils.isFunction)(appliedFunction)) {
84
+ let fnValue = getOnOrPropsEvent(param, element);
85
+ if ((0, import_utils.isString)(fnValue)) {
86
+ fnValue = import_utils.getContextFunction.call(element, fnValue);
87
+ }
88
+ if ((0, import_utils.isFunction)(fnValue)) {
84
89
  node.addEventListener(param, async (event) => {
85
90
  const { state, context } = element;
86
- await appliedFunction.call(
87
- element,
88
- event,
89
- element,
90
- state,
91
- context,
92
- options
93
- );
91
+ await fnValue.call(element, event, element, state, context, options);
94
92
  });
95
93
  }
96
94
  }
package/dist/esm/on.js CHANGED
@@ -1,13 +1,14 @@
1
- import { isFunction } from "@domql/utils";
1
+ import { isFunction, isString, getContextFunction } from "@domql/utils";
2
2
  const getOnOrPropsEvent = (param, element) => {
3
3
  var _a, _b;
4
4
  const onEvent = (_a = element.on) == null ? void 0 : _a[param];
5
5
  const onPropEvent = (_b = element.props) == null ? void 0 : _b["on" + param.slice(0, 1).toUpperCase() + param.slice(1)];
6
6
  return onEvent || onPropEvent;
7
7
  };
8
- const applyEvent = (param, element, state, context, options) => {
9
- if (!param.call) element.warn(`Event is not executable: ${param}`);
10
- return param.call(
8
+ const applyEvent = (fnValue, element, state, context, options) => {
9
+ if (isString(fnValue)) fnValue = getContextFunction.call(element, fnValue);
10
+ if (!fnValue.call) element.warn(`Event is not executable: ${fnValue}`);
11
+ return fnValue.call(
11
12
  element,
12
13
  element,
13
14
  state || element.state,
@@ -22,9 +23,10 @@ const triggerEventOn = async (param, element, options) => {
22
23
  return await applyEvent(appliedFunction, element, state, context, options);
23
24
  }
24
25
  };
25
- const applyEventUpdate = (param, updatedObj, element, state, context, options) => {
26
- if (!param.call) element.warn(`Event is not executable: ${param}`);
27
- return param.call(
26
+ const applyEventUpdate = (fnValue, updatedObj, element, state, context, options) => {
27
+ if (isString(fnValue)) fnValue = getContextFunction.call(element, fnValue);
28
+ if (!fnValue.call) element.warn(`Event is not executable: ${fnValue}`);
29
+ return fnValue.call(
28
30
  element,
29
31
  updatedObj,
30
32
  element,
@@ -52,18 +54,14 @@ const applyEventsOnNode = (element, options) => {
52
54
  for (const param in on) {
53
55
  if (param === "init" || param === "beforeClassAssign" || param === "render" || param === "renderRouter" || param === "attachNode" || param === "stateInit" || param === "stateCreated" || param === "beforeStateUpdate" || param === "stateUpdate" || param === "beforeUpdate" || param === "done" || param === "create" || param === "complete" || param === "frame" || param === "update")
54
56
  continue;
55
- const appliedFunction = getOnOrPropsEvent(param, element);
56
- if (isFunction(appliedFunction)) {
57
+ let fnValue = getOnOrPropsEvent(param, element);
58
+ if (isString(fnValue)) {
59
+ fnValue = getContextFunction.call(element, fnValue);
60
+ }
61
+ if (isFunction(fnValue)) {
57
62
  node.addEventListener(param, async (event) => {
58
63
  const { state, context } = element;
59
- await appliedFunction.call(
60
- element,
61
- event,
62
- element,
63
- state,
64
- context,
65
- options
66
- );
64
+ await fnValue.call(element, event, element, state, context, options);
67
65
  });
68
66
  }
69
67
  }
package/on.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- import { isFunction } from '@domql/utils'
3
+ import { isFunction, isString, getContextFunction } from '@domql/utils'
4
4
 
5
5
  const getOnOrPropsEvent = (param, element) => {
6
6
  const onEvent = element.on?.[param]
@@ -9,9 +9,10 @@ const getOnOrPropsEvent = (param, element) => {
9
9
  return onEvent || onPropEvent
10
10
  }
11
11
 
12
- export const applyEvent = (param, element, state, context, options) => {
13
- if (!param.call) element.warn(`Event is not executable: ${param}`)
14
- return param.call(
12
+ export const applyEvent = (fnValue, element, state, context, options) => {
13
+ if (isString(fnValue)) fnValue = getContextFunction.call(element, fnValue)
14
+ if (!fnValue.call) element.warn(`Event is not executable: ${fnValue}`)
15
+ return fnValue.call(
15
16
  element,
16
17
  element,
17
18
  state || element.state,
@@ -29,15 +30,16 @@ export const triggerEventOn = async (param, element, options) => {
29
30
  }
30
31
 
31
32
  export const applyEventUpdate = (
32
- param,
33
+ fnValue,
33
34
  updatedObj,
34
35
  element,
35
36
  state,
36
37
  context,
37
38
  options
38
39
  ) => {
39
- if (!param.call) element.warn(`Event is not executable: ${param}`)
40
- return param.call(
40
+ if (isString(fnValue)) fnValue = getContextFunction.call(element, fnValue)
41
+ if (!fnValue.call) element.warn(`Event is not executable: ${fnValue}`)
42
+ return fnValue.call(
41
43
  element,
42
44
  updatedObj,
43
45
  element,
@@ -89,18 +91,14 @@ export const applyEventsOnNode = (element, options) => {
89
91
  )
90
92
  continue
91
93
 
92
- const appliedFunction = getOnOrPropsEvent(param, element)
93
- if (isFunction(appliedFunction)) {
94
+ let fnValue = getOnOrPropsEvent(param, element)
95
+ if (isString(fnValue)) {
96
+ fnValue = getContextFunction.call(element, fnValue)
97
+ }
98
+ if (isFunction(fnValue)) {
94
99
  node.addEventListener(param, async (event) => {
95
100
  const { state, context } = element
96
- await appliedFunction.call(
97
- element,
98
- event,
99
- element,
100
- state,
101
- context,
102
- options
103
- )
101
+ await fnValue.call(element, event, element, state, context, options)
104
102
  })
105
103
  }
106
104
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/event",
3
- "version": "2.31.0",
3
+ "version": "2.31.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "index.js",
@@ -28,8 +28,8 @@
28
28
  "prepublish": "npm run build; npm run copy:package:cjs"
29
29
  },
30
30
  "dependencies": {
31
- "@domql/report": "^2.31.0",
32
- "@domql/utils": "^2.31.0"
31
+ "@domql/report": "^2.31.1",
32
+ "@domql/utils": "^2.31.1"
33
33
  },
34
- "gitHead": "dd5c64895320d678f28ca585c9fd4e4550a483cd"
34
+ "gitHead": "6ac409576cc3b2ac653e9601d5a8c2bed90b83de"
35
35
  }