@knowark/componarkjs 1.9.0 → 1.9.2
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.
|
@@ -260,6 +260,29 @@ describe('Component', () => {
|
|
|
260
260
|
expect(component.local).toEqual({ name: 'Sprite', brand: 'Coca-Cola' })
|
|
261
261
|
})
|
|
262
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
|
+
|
|
263
286
|
it('listens to events and handles them with its own methods', async () => {
|
|
264
287
|
container.innerHTML = `
|
|
265
288
|
<mock-component code="ABC123">
|
|
@@ -22,11 +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
|
-
if (pipe?.toLocaleLowerCase()
|
|
26
|
-
return set(this, objectPath.trim(),
|
|
27
|
-
event, eventPath, get(event, 'detail', ''))))
|
|
25
|
+
if (pipe?.toLocaleLowerCase() === 'object') {
|
|
26
|
+
return set(this, objectPath.trim(), event.detail)
|
|
28
27
|
}
|
|
29
|
-
|
|
28
|
+
set(this, objectPath.trim(), transform(pipe, get(
|
|
29
|
+
event, eventPath, get(event, 'detail', ''))))
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -94,7 +94,7 @@ function transform (pipe, value) {
|
|
|
94
94
|
return {
|
|
95
95
|
string: String,
|
|
96
96
|
boolean: Boolean,
|
|
97
|
-
number: Number
|
|
97
|
+
number: (value) => Number(String(value).replace(',', ''))
|
|
98
98
|
}[pipe?.toLowerCase() || 'string'](value)
|
|
99
99
|
}
|
|
100
100
|
|