Skip to content

Commit

Permalink
Add vuex support
Browse files Browse the repository at this point in the history
  • Loading branch information
marconi1992 committed Mar 17, 2019
1 parent 67762fb commit 1f033ae
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hypernova-vue",
"version": "1.0.0",
"version": "1.1.0",
"description": "Vue bindings for Hypernova",
"main": "lib/index.js",
"author": "Felipe Guizar Diaz <felipegaiacharly@gmail.com>",
Expand Down
36 changes: 36 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,39 @@ export const renderVue = (name, Component) => hypernova({
return Component;
},
});


export const renderVuex = (name, Component) => hypernova({
server() {
return async (propsData) => {
const vm = new Component({
propsData,
});

const renderer = createRenderer();

const contents = await renderer.renderToString(vm);

return serialize(name, contents, { propsData, state: vm.$store.state });
};
},

client() {
const payloads = load(name);
if (payloads) {
payloads.forEach((payload) => {
const { node, data } = payload;
const { propsData, state } = data;
const vm = new Component({
propsData,
});

vm.$store.replaceState(state);

vm.$mount(node.children[0]);
});
}

return Component;
},
});

0 comments on commit 1f033ae

Please sign in to comment.