revue
Redux binding for Vue.
Last updated 4 years ago by rem .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install revue 
SYNC missed versions from official npm registry.

Revue

NPM version Build Status donate

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'
// create the logic how you would update the todos
import todos from './reducers/todos'
// create some redux actions
import actions from './actions'

// create a redux store
const reduxStore = createStore(todos)
// binding the store to Vue instance, actions are optional
const store = new Revue(Vue, reduxStore, actions)
// expose the store for your component to use
export default store

actions/todos.js

// create actionCreators yourself or use `redux-actions`
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')
      //=> subscribe state.todos to vm.todos
      // if prop is not in top level
      // do this.$select('todos as path.to.todos')
    }
  },
  methods: {
    addTodo() {
      store.dispatch({type: 'ADD_TODO', this.todo})
      // or use the actionCreator
      store.dispatch(todoActions.addTodo(this.todo))
      // also equal to: (if you binded actions when creating the store)
      const {addTodo} = store.actions
      store.dispatch(addTodo(this.todo))
    }
  }
}

More detailed usages

Recipes ????

Development

  • npm test run unit test
  • npm run example run webpack example

License

MIT © EGOIST

Current Tags

  • 3.0.0                                ...           latest (4 years ago)

42 Versions

  • 3.0.0                                ...           4 years ago
  • 2.2.0                                ...           4 years ago
  • 2.1.3                                ...           5 years ago
  • 2.1.2                                ...           5 years ago
  • 2.1.1                                ...           5 years ago
  • 2.1.0                                ...           5 years ago
  • 2.0.2                                ...           5 years ago
  • 2.0.1                                ...           5 years ago
  • 2.0.0                                ...           5 years ago
  • 2.0.0-rc1                                ...           5 years ago
  • 2.0.0-beta2                                ...           5 years ago
  • 2.0.0-beta1                                ...           5 years ago
  • 1.3.0                                ...           5 years ago
  • 2.0.0-alpha                                ...           5 years ago
  • 1.2.6                                ...           5 years ago
  • 1.2.5                                ...           5 years ago
  • 1.2.44                                ...           5 years ago
  • 1.2.43                                ...           5 years ago
  • 1.2.42                                ...           5 years ago
  • 1.2.41                                ...           5 years ago
  • 1.2.4                                ...           5 years ago
  • 1.2.34                                ...           5 years ago
  • 1.2.33                                ...           5 years ago
  • 1.2.32                                ...           5 years ago
  • 1.2.31                                ...           5 years ago
  • 1.2.21                                ...           5 years ago
  • 1.2.2                                ...           5 years ago
  • 1.2.1                                ...           5 years ago
  • 1.2.0                                ...           5 years ago
  • 1.1.1                                ...           5 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.32                                ...           5 years ago
  • 1.0.31                                ...           5 years ago
  • 1.0.3                                ...           5 years ago
  • 1.0.24                                ...           5 years ago
  • 1.0.23                                ...           5 years ago
  • 1.0.22                                ...           5 years ago
  • 1.0.21                                ...           5 years ago
  • 1.0.2                                ...           5 years ago
  • 1.0.11                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (16)

Copyright 2014 - 2016 © taobao.org |