Revue
Learn Redux before using Revue. That would help you get rid of JavaScript fatigue, sort of.
Usage
Obviously it works with Redux, install via NPM: npm i --save redux revue
You can also hot-link the CDN version: https://npmcdn.com/revue/dist/revue.js, Revue
is exposed to window
object.
The Gist
You can try it online! http://esnextb.in/?gist=b300931ac26da8e9de2f
store.js
import Vue from 'vue'
import Revue from 'revue'
import {createStore} from 'redux'
import todos from './reducers/todos'
import actions from './actions'
const reduxStore = createStore(todos)
const store = new Revue(Vue, reduxStore, actions)
export default store
actions/todos.js
export function addTodo(payload) {
return {type: 'ADD_TODO', payload}
}
export function toggleTodo(payload) {
return {type: 'TOGGLE_TODO', payload}
}
component.js
When creating a Vue component that needs to react to data from Redux's store, you must specify the bindings between the data of the component and the data in the store. The following is an example of binding the data todo
in the component with store.getState().todos
by using the special function this.$select('todos')
.
import store from './store'
import * as todoActions from './actions/todo'
export default {
data() {
return {
todo: '',
todos: this.$select('todos')
}
},
methods: {
addTodo() {
store.dispatch({type: 'ADD_TODO', this.todo})
store.dispatch(todoActions.addTodo(this.todo))
const {addTodo} = store.actions
store.dispatch(addTodo(this.todo))
}
}
}
More detailed usages
Development
- npm test run unit test
- npm run example run webpack example
License
MIT © EGOIST