Skip to content

Commit

Permalink
update _ssr to _state
Browse files Browse the repository at this point in the history
  • Loading branch information
jescalan committed May 16, 2017
1 parent 528e508 commit 9e9e53e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/reshape-ast-to-vdom.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export default function toVnode (components, node, originalHtml) {
for (let k in node.attrs) {
props[k] = node.attrs[k].map((n) => n.content).join('')
}
// if there is a compressed original source, add it as _ssr prop
if (originalHtml) { props._ssr = originalHtml }
// if there is a compressed original source, add it as _state prop
if (originalHtml) { props._state = originalHtml }
// content is either a string, a subtree, or there isn't any
if (typeof node.content === 'string') {
return h(name, props, node.content)
Expand Down
18 changes: 9 additions & 9 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const preact = require('preact')
const h = preact.h
const {render} = require('preact-render-to-string')
const reshape = require('reshape')
const ssr = require('..')
const components = require('..')
const test = require('ava')
const {JSDOM} = require('jsdom')
const fs = require('fs')
Expand All @@ -16,7 +16,7 @@ test('basic', (t) => {

const html = "<my-component foo='bar' />"

return reshape({ plugins: [ssr({ 'my-component': MyComponent })] })
return reshape({ plugins: [components({ 'my-component': MyComponent })] })
.process(html)
.then((res) => {
t.is(res.output(), '<p>the value of foo is "bar"</p>')
Expand All @@ -30,7 +30,7 @@ test('multi element, different props', (t) => {

const html = "<my-component foo='bar' /><p>wow</p><my-component foo='wow' />"

return reshape({ plugins: [ssr({ 'my-component': MyComponent })] })
return reshape({ plugins: [components({ 'my-component': MyComponent })] })
.process(html)
.then((res) => {
t.is(res.output(), '<p>the value of foo is "bar"</p><p>wow</p><p>the value of foo is "wow"</p>')
Expand All @@ -48,7 +48,7 @@ test('renders children', (t) => {

const html = "<my-component foo='bar'><p>wow</p><div><c2></c2></div></my-component>"

return reshape({ plugins: [ssr({ 'my-component': MyComponent, c2 })] })
return reshape({ plugins: [components({ 'my-component': MyComponent, c2 })] })
.process(html)
.then((res) => {
t.is(res.output(), '<div class="parent">hello<p>wow</p><div><div class="wow">hello from c2</div></div></div>')
Expand All @@ -57,14 +57,14 @@ test('renders children', (t) => {

test('initial state rehydration', (t) => {
const component = `
function MyComponent ({ foo, _ssr }) {
return preact.h('p', { 'data-state': _ssr }, 'the value of foo is "' + foo + '"')
function MyComponent ({ foo, _state }) {
return preact.h('p', { 'data-state': _state }, 'the value of foo is "' + foo + '"')
}
`
const MyComponent = eval(`${component}; MyComponent`)
const html = "<my-component foo='bar' />"

return reshape({ plugins: [ssr({ 'my-component': MyComponent })] })
return reshape({ plugins: [components({ 'my-component': MyComponent })] })
.process(html)
.then((res) => {
const dom = new JSDOM(`
Expand All @@ -89,8 +89,8 @@ test('initial state rehydration', (t) => {

test('node encode and decode', (t) => {
const data = JSON.stringify({ foo: 'bar' })
const encoded = ssr.encode(data)
const decoded = ssr.decode(encoded)
const encoded = components.encode(data)
const decoded = components.decode(encoded)
t.is(data, decoded)
})

Expand Down

0 comments on commit 9e9e53e

Please sign in to comment.