@knowark/componarkjs 1.8.3 → 1.9.0
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,23 @@ 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
|
+
|
|
246
263
|
it('listens to events and handles them with its own methods', async () => {
|
|
247
264
|
container.innerHTML = `
|
|
248
265
|
<mock-component code="ABC123">
|
|
@@ -22,8 +22,11 @@ export function listen (self) {
|
|
|
22
22
|
let [objectPath, eventPath] = content.split('=')
|
|
23
23
|
eventPath = eventPath?.trim() || 'target.value'
|
|
24
24
|
handler = function (event) {
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
if (pipe?.toLocaleLowerCase() !== 'object') {
|
|
26
|
+
return set(this, objectPath.trim(), transform(pipe, get(
|
|
27
|
+
event, eventPath, get(event, 'detail', ''))))
|
|
28
|
+
}
|
|
29
|
+
Object.assign(this[objectPath.trim()], event.detail)
|
|
27
30
|
}
|
|
28
31
|
}
|
|
29
32
|
|