Skip to content

Commit

Permalink
Lazy nodes support from V2
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew committed May 13, 2020
1 parent 5a49378 commit cb8dad0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ function resolveNode(node, state, actions) {
if (typeof node === 'function') {
return resolveNode(node(state, actions), state, actions)
}
if (node && node.type === 2) {
return resolveNode(node.lazy.view(node.lazy), state, actions)
}

return node
}
Expand Down
29 changes: 29 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,35 @@ describe('renderToString(view, state, actions)', () => {
expect(html).toBe('<div>foo bar baz</div>')
})

it('should support Hyperapp V2 lazy nodes', () => {
const VNode = {
lazy: {
view: ({ name }) => <div>{name}</div>,
name: 'foo',
},
type: 2,
}
const html = renderToString(VNode)
expect(html).toBe('<div>foo</div>')
})

it('should support Hyperapp V2 nested lazy nodes', () => {
const VNode = {
lazy: {
view: () => ({
lazy: {
view: ({ name }) => <div>{name}</div>,
name: 'foo',
},
type: 2,
}),
},
type: 2,
}
const html = renderToString(VNode)
expect(html).toBe('<div>foo</div>')
})

it('should render counter', () => {
const testState = { count: 100 }
const testActions = {
Expand Down

0 comments on commit cb8dad0

Please sign in to comment.