@knowark/componarkjs 1.7.5 → 1.7.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.
|
@@ -244,7 +244,7 @@ describe('Component', () => {
|
|
|
244
244
|
it('listens to events and redirects them to target components', async () => {
|
|
245
245
|
container.innerHTML = `
|
|
246
246
|
<mock-component code="ABC123">
|
|
247
|
-
<input type="text" listen on-alter="customHandler
|
|
247
|
+
<input type="text" listen on-alter="customHandler@#child"></input>
|
|
248
248
|
<mock-component id="child" code="XYZ890"></mock-component>
|
|
249
249
|
</mock-component>
|
|
250
250
|
`
|
|
@@ -7,9 +7,10 @@ export function listen (self) {
|
|
|
7
7
|
for (const element of elements) {
|
|
8
8
|
for (const attribute of Array.from(element.attributes)) {
|
|
9
9
|
if (attribute.name.startsWith('on-')) {
|
|
10
|
-
|
|
10
|
+
const [value, at] = attribute.value.split('@').map(item => item.trim())
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
let handler = self[value]
|
|
13
|
+
const [assignment] = value.match(/[^{{]+(?=\}})/g) || []
|
|
13
14
|
|
|
14
15
|
if (assignment) {
|
|
15
16
|
let [objectPath, eventPath] = assignment.split('=')
|
|
@@ -22,11 +23,11 @@ export function listen (self) {
|
|
|
22
23
|
|
|
23
24
|
if (!handler) continue
|
|
24
25
|
|
|
25
|
-
const at = element.getAttribute('at')
|
|
26
|
+
// const at = element.getAttribute('at')
|
|
26
27
|
const catchingHandler = async function (event) {
|
|
27
28
|
try {
|
|
28
29
|
let receiver = this
|
|
29
|
-
if (at) receiver = this.
|
|
30
|
+
if (at) receiver = this.querySelector(at)
|
|
30
31
|
return await Promise.resolve(handler.bind(receiver)(event))
|
|
31
32
|
} catch (error) {
|
|
32
33
|
this.dispatchEvent(
|