@knowark/componarkjs 1.7.7 → 1.7.9
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.
|
@@ -13,7 +13,7 @@ class MockComponent extends Component {
|
|
|
13
13
|
reflectedProperties () { return ['code'] }
|
|
14
14
|
|
|
15
15
|
customHandler (/** @type {CustomEvent} */ event) {
|
|
16
|
-
event.detail.code
|
|
16
|
+
event.detail.code.push(this.code)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
erroringHandler (_event) {
|
|
@@ -235,10 +235,10 @@ describe('Component', () => {
|
|
|
235
235
|
const input = component.select('input')
|
|
236
236
|
|
|
237
237
|
const event = new globalThis.CustomEvent(
|
|
238
|
-
'alter', { bubbles: true, detail: { code:
|
|
238
|
+
'alter', { bubbles: true, detail: { code: [] } })
|
|
239
239
|
input.dispatchEvent(event)
|
|
240
240
|
|
|
241
|
-
expect(event.detail.code).toEqual('ABC123')
|
|
241
|
+
expect(event.detail.code).toEqual(['ABC123'])
|
|
242
242
|
})
|
|
243
243
|
|
|
244
244
|
it('listens to events and redirects them to target components', async () => {
|
|
@@ -253,10 +253,30 @@ describe('Component', () => {
|
|
|
253
253
|
const input = component.select('input')
|
|
254
254
|
|
|
255
255
|
const event = new globalThis.CustomEvent(
|
|
256
|
-
'alter', { bubbles: true, detail: { code:
|
|
256
|
+
'alter', { bubbles: true, detail: { code: [] } })
|
|
257
257
|
input.dispatchEvent(event)
|
|
258
258
|
|
|
259
|
-
expect(event.detail.code).toEqual('XYZ890')
|
|
259
|
+
expect(event.detail.code).toEqual(['XYZ890'])
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
it('listens to clicks and redirects them to target components', async () => {
|
|
263
|
+
container.innerHTML = `
|
|
264
|
+
<mock-component code="ABC123">
|
|
265
|
+
<div type="text" listen on-click="customHandler@#child">
|
|
266
|
+
<button id="action">Action</button>
|
|
267
|
+
</div>
|
|
268
|
+
<mock-component id="child" code="XYZ890"></mock-component>
|
|
269
|
+
</mock-component>
|
|
270
|
+
`
|
|
271
|
+
|
|
272
|
+
const component = container.querySelector('mock-component')
|
|
273
|
+
const button = component.select('#action')
|
|
274
|
+
|
|
275
|
+
const event = new globalThis.CustomEvent(
|
|
276
|
+
'click', { bubbles: true, detail: { code: [] } })
|
|
277
|
+
button.dispatchEvent(event)
|
|
278
|
+
|
|
279
|
+
expect(event.detail.code).toEqual(['XYZ890'])
|
|
260
280
|
})
|
|
261
281
|
|
|
262
282
|
it('emits an error event on declared listeners', async () => {
|
|
@@ -21,13 +21,16 @@ export function listen (self) {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
if (!handler) continue
|
|
24
|
+
if (!handler && !at) continue
|
|
25
25
|
|
|
26
26
|
// const at = element.getAttribute('at')
|
|
27
27
|
const catchingHandler = async function (event) {
|
|
28
28
|
try {
|
|
29
29
|
let receiver = this
|
|
30
|
-
if (at)
|
|
30
|
+
if (at) {
|
|
31
|
+
receiver = this.querySelector(at)
|
|
32
|
+
handler = receiver[value]
|
|
33
|
+
}
|
|
31
34
|
return await Promise.resolve(handler.bind(receiver)(event))
|
|
32
35
|
} catch (error) {
|
|
33
36
|
this.dispatchEvent(
|