Skip to content

Commit

Permalink
Automatically join arrays
Browse files Browse the repository at this point in the history
Signed-off-by: macdonst <[email protected]>
  • Loading branch information
macdonst committed Nov 30, 2023
1 parent f7af3b1 commit 45a8070
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion lib/transcode.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export function encode(value) {
else if (typeof value == 'number' ) {
return value
}
else if (Array.isArray(value) && value.every(i => typeof i === "string") ) {
return value.join('')
}
else {
const id = `__b_${place++}`
map[id] = value
Expand All @@ -18,4 +21,4 @@ export function decode(value) {
return value.startsWith('__b_')
? map[value]
: value
}
}
4 changes: 2 additions & 2 deletions test/enhance.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ test('Passing state through multiple levels', t => {
<my-pre-page items="${items}"></my-pre-page>
`
const expected = `
<my-pre-page items="">
<my-pre items="">
<my-pre-page items="test">
<my-pre items="test">
<pre>test</pre>
</my-pre>
</my-pre-page>
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/templates/my-pre.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default function MyMoreContent({ html, state }) {
const { items=[] } = state?.attrs
return html`<pre>${items[0]}</pre >`
const { items='' } = state?.attrs
return html`<pre>${items}</pre >`
}

0 comments on commit 45a8070

Please sign in to comment.