UNPKG

3.27 kBMarkdownView Raw
1<h1 align="center">Revue</h1>
2
3<p align="center">
4 <a href="https://www.npmjs.com/package/revue">
5 <img src="https://camo.githubusercontent.com/b145895dcb12693255d3b4b371446ea6b73fa357/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f762f72657675652e737667" alt="NPM version" style="max-width:100%;">
6 </a>
7 <a href="https://www.npmjs.com/package/revue">
8 <img src="https://camo.githubusercontent.com/49a99ffd8da7a0793e1d648f859792e9b1db45fa/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f646d2f72657675652e737667" alt="NPM download" style="max-width:100%;"></a>
9 <a href="https://travis-ci.org/egoist/revue">
10 <img src="https://img.shields.io/travis/egoist/revue/master.svg" alt="Build Status" style="max-width:100%;">
11 </a>
12 <img src="https://img.shields.io/badge/stablity-experimental-red.svg">
13</p>
14
15> Learn [Redux](http://redux.js.org/) before using Revue. That would help you get rid of JavaScript fatigue, sort of.
16
17## Usage
18
19Obviously it works with Redux, install via NPM: `npm i --save redux revue`
20
21You can also hot-link the CDN version: https://npmcdn.com/revue/revue.js, `Revue` is exposed to `window` object.
22
23## The Gist
24
25You can try it online! http://esnextb.in/?gist=b300931ac26da8e9de2f
26
27**store.js**
28
29```js
30import Vue from 'vue'
31import Revue from 'revue'
32import {createStore} from 'redux'
33// create the logic how you would update the todos
34import todos from './reducers/todos'
35// create some redux actions
36import actions from './actions'
37
38// create a redux store
39const reduxStore = createStore(todos)
40// binding the store to Vue instance, actions are optional
41const store = new Revue(Vue, reduxStore, actions)
42// expose the store for your component to use
43export default store
44```
45
46**actions/todos.js**
47
48```js
49// create actionCreators yourself or use `redux-actions`
50export function addTodo(payload) {
51 return {type: 'ADD_TODO', payload}
52}
53export function toggleTodo(payload) {
54 return {type: 'TOGGLE_TODO', payload}
55}
56```
57
58**component.js**
59
60```js
61import store from './store'
62import * as todoActions from './actions/todo'
63
64export default {
65 data() {
66 return {
67 todo: '',
68 todos: this.$select('todos')
69 //=> subscribe state.todos to vm.todos
70 // if prop is not in top level
71 // do this.$select('todos as path.to.todos')
72 }
73 },
74 methods: {
75 addTodo() {
76 store.dispatch({type: 'ADD_TODO', this.todo})
77 // or use the actionCreator
78 store.dispatch(todoActions.addTodo(this.todo))
79 // also equal to: (if you binded actions when creating the store)
80 const {addTodo} = store.actions
81 store.dispatch(addTodo(this.todo))
82 }
83 }
84}
85```
86
87[**More detailed usages**](/example)
88
89## [Recipes](https://github.com/revue/revue/issues?q=is%3Aissue+is%3Aclosed+label%3Arecipe) 🍳
90
91- [Use webpack alias to resolve store.js](https://github.com/revue/revue/issues/8)
92- [Using bindActionCreators](https://github.com/revue/revue/issues/7)
93
94## Development
95
96- **npm test** run unit test
97- **npm run watch** build example
98- **serve example** serve example
99- **make publish** publish a new version
100- **npm run cjs** build in CommonJS format
101- **npm run umd** build in umd format
102- **npm run demo** to publish demo to surge
103
104## License
105
106MIT &copy; [EGOIST](https://github.com/egoist)