Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically join arrays #56

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 >`
}