@knowark/componarkjs 1.8.4 → 1.9.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.
|
@@ -243,6 +243,46 @@ describe('Component', () => {
|
|
|
243
243
|
expect(component.data.value).toEqual(777)
|
|
244
244
|
})
|
|
245
245
|
|
|
246
|
+
it('performs object assignment of event details', async () => {
|
|
247
|
+
container.innerHTML = `
|
|
248
|
+
<mock-component>
|
|
249
|
+
<input type="text" listen on-alter="{{ local | object }}"></input>
|
|
250
|
+
</mock-component>
|
|
251
|
+
`
|
|
252
|
+
|
|
253
|
+
const component = container.querySelector('mock-component')
|
|
254
|
+
const input = component.select('input')
|
|
255
|
+
|
|
256
|
+
const detail = { name: 'Sprite', brand: 'Coca-Cola' }
|
|
257
|
+
input.dispatchEvent(
|
|
258
|
+
new globalThis.CustomEvent('alter', { bubbles: true, detail }))
|
|
259
|
+
|
|
260
|
+
expect(component.local).toEqual({ name: 'Sprite', brand: 'Coca-Cola' })
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
it('performs nested object assignment of event details', async () => {
|
|
264
|
+
container.innerHTML = `
|
|
265
|
+
<mock-component>
|
|
266
|
+
<input type="text" listen on-alter="{{ local.zone | object }}"></input>
|
|
267
|
+
</mock-component>
|
|
268
|
+
`
|
|
269
|
+
|
|
270
|
+
const component = container.querySelector('mock-component')
|
|
271
|
+
component.local.zone = {}
|
|
272
|
+
const input = component.select('input')
|
|
273
|
+
|
|
274
|
+
const detail = { country: 'USA', city: 'Atlanta' }
|
|
275
|
+
input.dispatchEvent(
|
|
276
|
+
new globalThis.CustomEvent('alter', { bubbles: true, detail }))
|
|
277
|
+
|
|
278
|
+
expect(component.local).toEqual({
|
|
279
|
+
zone: {
|
|
280
|
+
country: 'USA',
|
|
281
|
+
city: 'Atlanta'
|
|
282
|
+
}
|
|
283
|
+
})
|
|
284
|
+
})
|
|
285
|
+
|
|
246
286
|
it('listens to events and handles them with its own methods', async () => {
|
|
247
287
|
container.innerHTML = `
|
|
248
288
|
<mock-component code="ABC123">
|
|
@@ -22,6 +22,9 @@ export function listen (self) {
|
|
|
22
22
|
let [objectPath, eventPath] = content.split('=')
|
|
23
23
|
eventPath = eventPath?.trim() || 'target.value'
|
|
24
24
|
handler = function (event) {
|
|
25
|
+
if (pipe?.toLocaleLowerCase() === 'object') {
|
|
26
|
+
return set(this, objectPath.trim(), event.detail)
|
|
27
|
+
}
|
|
25
28
|
set(this, objectPath.trim(), transform(pipe, get(
|
|
26
29
|
event, eventPath, get(event, 'detail', ''))))
|
|
27
30
|
}
|