JSFiddle - React, Tailwind, and code Playground
by will ye
HTML
<script src="https://unpkg.com/vue"></script>
<script src="https://unpkg.com/vuex"></script>
<script src="https://rawgit.com/ye-will/vue-factory/master/vue-factory.min.js"></script>
<div id="app">
<disp-counter></disp-counter>
<mut-counter></mut-counter>
</div>
<script type="x-template" id="disp">
<p>{{ state.count }}</p>
</script>
<script type="x-template" id="mut">
<p>
<button @click="mutations.increment()">+</button>
<button @click="mutations.decrement()">-</button>
</p>
</script>
Babel + JSX
// make sure to call Vue.use(Vuex) && Vue.use(VueFactory)
// if using a module system
let ctx = new Vuex.Store({
state: {
count: 0
},
mutations: {
increment: state => state.count++,
decrement: state => state.count--
}
})
class StoreMut {
constructor (ctx) {
this._store = ctx
}
increment () {
this._store.commit('increment')
}
decrement () {
this._store.commit('decrement')
}
}
class StoreState {
constructor (ctx) {
this._store = ctx
}
get count () {
return this._store.state.count
}
}
Vue.factory.register({
mutations: new StoreMut(ctx),
state: new StoreState(ctx)
})
const app = new Vue({
el: '#app',
components: {
'disp-counter' : {
template: '#disp',
providers: ['state']
},
'mut-counter' :{
template: '#mut',
providers: ['mutations']
}
}
})