Skip to content

Commit 0ba5af9

Browse files
author
Timothy Johnson
committed
Use flatMap
1 parent 871f49e commit 0ba5af9

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

src/client/index.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,14 @@ function serializeNode(node) {
9191
: Object.keys(internal.props)
9292
const ctx = clone(internal.ctx)
9393
serialized.detail = {
94-
attributes: props.reduce((o, key) => {
95-
const value = ctx[key]
96-
if (value === undefined) return o
97-
94+
attributes: props.flatMap(key => {
9895
delete ctx[key]
99-
o.push({ key, value, isBound: key in internal.bound })
100-
return o
101-
}, []),
102-
listeners: Object.entries(internal.callbacks).reduce(
103-
(list, [event, value]) =>
104-
list.concat(value.map(o => ({ event, handler: o.toString() }))),
105-
[]
96+
return ctx[key] === undefined
97+
? []
98+
: { key, value: ctx[key], isBound: key in internal.bound }
99+
}),
100+
listeners: Object.entries(internal.callbacks).flatMap(
101+
([event, value]) => value.map(o => ({ event, handler: o.toString() }))
106102
),
107103
ctx: Object.entries(ctx).map(([key, value]) => ({ key, value }))
108104
}

0 commit comments

Comments
 (0)