Skip to content

Commit

Permalink
Support multiple vuex stores
Browse files Browse the repository at this point in the history
  • Loading branch information
marconi1992 committed Mar 17, 2019
1 parent 0ea7705 commit ed92300
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,8 @@ export default renderVue('Header', Header)

```js
import { renderVuex, Vue } from 'hypernova-vue'
import store from './store'
import createStore from './store'
import HeaderComponent from './components/HeaderComponent.vue'

const Header = Vue.extend({
...HeaderComponent,
store
})

export default renderVuex('Header', Header)
export default renderVuex('Header', HeaderComponent, createStore)
```
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.1.0",
"version": "2.0.0",
"description": "Vue bindings for Hypernova",
"main": "lib/index.js",
"author": "Felipe Guizar Diaz <[email protected]>",
Expand Down
18 changes: 16 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,16 @@ export const renderVue = (name, Component) => hypernova({
});


export const renderVuex = (name, Component) => hypernova({
export const renderVuex = (name, ComponentDefinition, createStore) => hypernova({
server() {
return async (propsData) => {
const store = createStore();

const Component = Vue.extend({
...ComponentDefinition,
store,
});

const vm = new Component({
propsData,
});
Expand All @@ -59,6 +66,13 @@ export const renderVuex = (name, Component) => hypernova({
payloads.forEach((payload) => {
const { node, data } = payload;
const { propsData, state } = data;
const store = createStore();

const Component = Vue.extend({
...ComponentDefinition,
store,
});

const vm = new Component({
propsData,
});
Expand All @@ -69,6 +83,6 @@ export const renderVuex = (name, Component) => hypernova({
});
}

return Component;
return ComponentDefinition;
},
});

0 comments on commit ed92300

Please sign in to comment.