├── .babelrc ├── .editorconfig ├── .gitignore ├── .npmignore ├── .prettierignore ├── .prettierrc.js ├── .travis.yml ├── README.md ├── bundle.es.js ├── bundle.js ├── examples ├── counter │ ├── .babelrc │ ├── package-lock.json │ ├── package.json │ └── src │ │ ├── Actions │ │ ├── index.js │ │ └── types.js │ │ ├── Components │ │ ├── Counter.vue │ │ └── CounterProvider.vue │ │ ├── Reducers │ │ └── Counter.js │ │ ├── index.html │ │ └── index.js └── counterJsx │ ├── .babelrc │ ├── package-lock.json │ ├── package.json │ └── src │ ├── Actions │ ├── index.js │ └── types.js │ ├── Components │ ├── Counter.vue │ └── CounterProvider.jsx │ ├── Reducers │ └── Counter.js │ ├── index.html │ └── index.js ├── index.js ├── package-lock.json ├── package.json ├── rollup.config.js └── tests ├── StoreProvider.vue ├── TwoStoreProvider.vue ├── provider.spec.js ├── test.vue └── testTwoStore.vue /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | [ 4 | "@babel/env", 5 | { 6 | "targets": { 7 | "ie": "11" 8 | }, 9 | "modules": false 10 | } 11 | ] 12 | ], 13 | "env": { 14 | "testing": { 15 | "presets": ["@babel/env"] 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_size = 2 5 | indent_style = space -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | # 3 | node_modules/ 4 | yarn* 5 | .idea/ 6 | .cache/ 7 | dist/ 8 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | examples/ 3 | tests/ -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | bundle.js 2 | bundle.es.js -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | trailingComma: 'es5', 3 | tabWidth: 2, 4 | semi: false, 5 | singleQuote: true, 6 | } 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # https://docs.travis-ci.com/user/getting-started/ 2 | language: node_js 3 | 4 | node_js: 5 | - '10' 6 | script: yarn && yarn test && pushd ./examples/counter && yarn && yarn build && popd && pushd ./examples/counterJsx && yarn && yarn build && popd 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vuejs-redux 2 | 3 | [![npm version](https://badge.fury.io/js/vuejs-redux.svg)](https://badge.fury.io/js/vuejs-redux) 4 | [![Build Status](https://travis-ci.com/titouancreach/vuejs-redux.svg?branch=master)](https://travis-ci.com/titouancreach/vuejs-redux) 5 | [![GitHub contributors](https://img.shields.io/github/contributors/titouancreach/vuejs-redux.svg)](https://github.com/titouancreach/vuejs-redux/graphs/contributors/) 6 | [![Say Thanks!](https://img.shields.io/badge/Say%20Thanks-!-1EAEDB.svg)](https://saythanks.io/to/titouancreach) 7 | 8 | ## Description 9 | 10 | Flexible binding between Vue and Redux, allowing use of multiple stores. 11 | It works, in the same way, like render props does in React. It uses Scoped Slot - [read my article about it](https://medium.com/@titouan.creach_44544/emulate-render-props-in-vuejs-c14086dc8dfa). 12 | 13 | _Note:_ 14 | The previous version was using Higher Order Components (HOC); this version uses Scoped slots instead. 15 | No more magic with the connect methods. Everything is explicit which will prevent props collision 16 | and an [ugly trick with the render function](https://github.com/vuejs/vue/issues/6201). 17 | 18 | Why you should use it: 19 | 20 | - Just 45 lines of code. 21 | - No dependencies at all 22 | - Easy to read, understand, and extend. 23 | - Same API as [react-redux](https://github.com/reactjs/react-redux). 24 | - Combine multiple Providers to be populated by multiple sources. 25 | - No hard coded dependencies between 'Vue' and the store, so more composable. 26 | - Doesn't polluate `data`, so you can use the power of the `functional component` 27 | - Debuggable in the [Vue devtool browser extension](https://github.com/vuejs/vue-devtools). 28 | - Elegant JSX syntax. 29 | 30 | # Table of Contents 31 | 32 | - [vuejs-redux](#vuejs-redux) 33 | - [Description](#description) 34 | - [Install](#install) 35 | - [Counter example](#counter-example) 36 | - [Multiple stores](#multiple-stores) 37 | - [Avoid passing the store to every <Provider ...>](#avoid-passing-the-store-to-every-provider-) 38 | - [Running the examples locally](#running-the-examples-locally) 39 | - [Testing](#testing) 40 | - [Rematch](#rematch) 41 | - [Live examples](#live-examples) 42 | - [CONTRIBUTING](#contributing) 43 | 44 | Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc) 45 | 46 | ## Install 47 | 48 | ``` 49 | npm install --save vuejs-redux 50 | ``` 51 | 52 | ## Counter example 53 | 54 | Let's build a counter app. The full code can be found in the `example/` directory. 55 | 56 | Start with a reducer: 57 | 58 | ```javascript 59 | export function counter(state = 0, action) { 60 | switch (action.type) { 61 | case 'INCREMENT': 62 | return state + 1 63 | case 'DECREMENT': 64 | return state - 1 65 | case 'RESET': 66 | return 0 67 | default: 68 | return state 69 | } 70 | } 71 | ``` 72 | 73 | Create the action creators in order to update our state: 74 | 75 | ```javascript 76 | export function increment() { 77 | return { type: 'INCREMENT' } 78 | } 79 | 80 | export function decrement() { 81 | return { type: 'DECREMENT' } 82 | } 83 | 84 | export function reset() { 85 | return { type: 'RESET' } 86 | } 87 | ``` 88 | 89 | We can now create the CounterProvider component. It acts as a Provider for our CounterComponent: 90 | 91 | ```vue 92 | 105 | 106 | 137 | ``` 138 | 139 | And finally our Counter component: 140 | 141 | ```vue 142 | 152 | 153 | 158 | ``` 159 | 160 | The Counter component is not aware that we are using redux. 161 | 162 | If you use JSX, you can use the same syntax as React render props: 163 | 164 | ```jsx 165 | render(h) { 166 | return ( 167 | 168 | {({actions, counterValue}) => ( 169 | 170 | )} 171 | 172 | ); 173 | }, 174 | ``` 175 | 176 | ## Multiple stores 177 | 178 | You can combine multiple store if needed, use the Provider component various times. 179 | You can obviously create an helper component or whatever to compose this. 180 | 181 | ```vue 182 |