egoist / zerotwo

😈 Refined state containter for Vue.js
75 stars 6 forks source link

Alternative API #8

Open egoist opened 6 years ago

egoist commented 6 years ago

https://github.com/jamiebuilds/unstated

<store-consumer>
    <button slot-scope={state}>{{state.count}}<button>
</store-consumer>
egoist commented 6 years ago
import zerotwo, { Store, Provider } from 'zerotwo'

Vue.use(zerotwo)

class CounterStore extends Store {
    state = {
        count: 0
    }

    inc = () => {
        this.state.count++
    }
}

new Vue({
    store: CounterStore,
    template: `
    <store-consumer>
        <div slot-scope="store">
            <button @click="store.inc">{{ store.state.count }}</button>
        </div>
    </store-consumer>
    `   
})