redux-vue 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +2 -2
- package/.editorconfig +15 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +17 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +11 -0
- package/.github/pull_request_template.md +8 -0
- package/.github/workflows/ci.yml +23 -0
- package/CODE_OF_CONDUCT.md +26 -0
- package/CONTRIBUTING.md +35 -0
- package/README.md +153 -79
- package/package.json +8 -7
- package/.npmignore +0 -5
- package/lib/connect.js +0 -122
- package/lib/index.js +0 -19
- package/lib/normalizeProps.js +0 -48
- package/lib/normalizeProps.spec.js +0 -22
- package/lib/reduxStorePlugin.js +0 -21
- package/yarn.lock +0 -1977
package/.babelrc
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
{
|
|
2
|
-
"presets": ["
|
|
3
|
-
}
|
|
2
|
+
"presets": [["@babel/preset-env", { "targets": { "node": "current" } }]]
|
|
3
|
+
}
|
package/.editorconfig
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# EditorConfig — https://editorconfig.org
|
|
2
|
+
root = true
|
|
3
|
+
|
|
4
|
+
[*]
|
|
5
|
+
charset = utf-8
|
|
6
|
+
end_of_line = lf
|
|
7
|
+
insert_final_newline = true
|
|
8
|
+
trim_trailing_whitespace = true
|
|
9
|
+
|
|
10
|
+
[*.{js,json,md,yml,yaml}]
|
|
11
|
+
indent_style = space
|
|
12
|
+
indent_size = 2
|
|
13
|
+
|
|
14
|
+
[*.md]
|
|
15
|
+
trim_trailing_whitespace = false
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Bug report
|
|
3
|
+
about: Something broken? Let us know.
|
|
4
|
+
labels: bug
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
**redux-vue version:**
|
|
8
|
+
**Vue version:**
|
|
9
|
+
**redux version:**
|
|
10
|
+
|
|
11
|
+
**Steps to reproduce:**
|
|
12
|
+
|
|
13
|
+
**Expected behaviour:**
|
|
14
|
+
|
|
15
|
+
**Actual behaviour:**
|
|
16
|
+
|
|
17
|
+
**Minimal reproduction (snippet or repo link):**
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [master]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [master]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
node-version: [18, 20]
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
18
|
+
uses: actions/setup-node@v4
|
|
19
|
+
with:
|
|
20
|
+
node-version: ${{ matrix.node-version }}
|
|
21
|
+
cache: npm
|
|
22
|
+
- run: npm ci
|
|
23
|
+
- run: npm test
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We pledge to make participation in this project a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity, level of experience, nationality, personal appearance, race, religion, or sexual identity.
|
|
6
|
+
|
|
7
|
+
## Our Standards
|
|
8
|
+
|
|
9
|
+
Positive behaviour includes:
|
|
10
|
+
- Using welcoming and inclusive language
|
|
11
|
+
- Being respectful of differing viewpoints
|
|
12
|
+
- Gracefully accepting constructive criticism
|
|
13
|
+
- Focusing on what is best for the community
|
|
14
|
+
|
|
15
|
+
Unacceptable behaviour includes:
|
|
16
|
+
- Harassment, trolling, or personal attacks
|
|
17
|
+
- Publishing others' private information without permission
|
|
18
|
+
- Other conduct which could reasonably be considered inappropriate
|
|
19
|
+
|
|
20
|
+
## Enforcement
|
|
21
|
+
|
|
22
|
+
Project maintainers may remove, edit, or reject comments, commits, code, issues, and other contributions not aligned with this Code of Conduct.
|
|
23
|
+
|
|
24
|
+
## Attribution
|
|
25
|
+
|
|
26
|
+
This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org/), version 2.1.
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Contributing to redux-vue
|
|
2
|
+
|
|
3
|
+
Thanks for taking the time to contribute!
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
git clone https://github.com/nadimtuhin/redux-vue.git
|
|
9
|
+
cd redux-vue
|
|
10
|
+
npm install
|
|
11
|
+
npm test
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Development Workflow
|
|
15
|
+
|
|
16
|
+
1. Fork the repo and create a branch: `git checkout -b fix/my-fix`
|
|
17
|
+
2. Write a failing test first (TDD — see `src/connect.spec.js` for examples)
|
|
18
|
+
3. Implement the fix / feature
|
|
19
|
+
4. Ensure all tests pass: `npm test`
|
|
20
|
+
5. Submit a pull request against `master`
|
|
21
|
+
|
|
22
|
+
## Pull Request Guidelines
|
|
23
|
+
|
|
24
|
+
- One concern per PR
|
|
25
|
+
- Include tests for any behaviour change
|
|
26
|
+
- Update README if you add a new API argument
|
|
27
|
+
- Keep commits conventional: `fix:`, `feat:`, `docs:`, `test:`
|
|
28
|
+
|
|
29
|
+
## Reporting Bugs
|
|
30
|
+
|
|
31
|
+
Use the GitHub issue tracker. Include:
|
|
32
|
+
- redux-vue version
|
|
33
|
+
- Vue version
|
|
34
|
+
- Minimal reproduction (snippet or repo link)
|
|
35
|
+
- Expected vs actual behaviour
|
package/README.md
CHANGED
|
@@ -1,110 +1,184 @@
|
|
|
1
|
-
# vue
|
|
2
|
-
|
|
1
|
+
# redux-vue
|
|
2
|
+
|
|
3
|
+
[](https://github.com/nadimtuhin/redux-vue/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/redux-vue)
|
|
5
|
+
[](https://www.npmjs.com/package/redux-vue)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
8
|
+
Redux bindings for **Vue 2** — a higher-order component (HOC) that connects Vue
|
|
9
|
+
components to a Redux store, similar to `react-redux`'s `connect()`.
|
|
10
|
+
|
|
11
|
+
> **Vue 2 only.** This library targets Vue 2.x. For Vue 3, use Pinia or `vuex` 4.x.
|
|
12
|
+
|
|
13
|
+
---
|
|
3
14
|
|
|
4
15
|
## Install
|
|
5
|
-
install through ``npm i redux-vue --save``
|
|
6
16
|
|
|
7
|
-
|
|
8
|
-
install
|
|
17
|
+
```bash
|
|
18
|
+
npm install redux-vue
|
|
19
|
+
# or
|
|
20
|
+
yarn add redux-vue
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Setup
|
|
24
|
+
|
|
25
|
+
Register the plugin on your root Vue instance so all child components can access
|
|
26
|
+
the store:
|
|
9
27
|
|
|
10
28
|
```js
|
|
11
29
|
// main.js
|
|
12
30
|
import Vue from 'vue';
|
|
13
31
|
import { reduxStorePlugin } from 'redux-vue';
|
|
14
|
-
import
|
|
15
|
-
import App from './
|
|
32
|
+
import store from './store';
|
|
33
|
+
import App from './App';
|
|
16
34
|
|
|
17
|
-
// install redux-vue
|
|
18
35
|
Vue.use(reduxStorePlugin);
|
|
19
36
|
|
|
20
37
|
new Vue({
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return <App />
|
|
24
|
-
}
|
|
38
|
+
store,
|
|
39
|
+
render: h => h(App),
|
|
25
40
|
});
|
|
26
41
|
```
|
|
27
42
|
|
|
43
|
+
## Usage
|
|
44
|
+
|
|
45
|
+
### `connect(mapStateToProps, mapDispatchToProps, [mergeProps])(Component)`
|
|
46
|
+
|
|
47
|
+
Wraps a Vue component and injects store state and dispatch functions as props.
|
|
48
|
+
|
|
28
49
|
```js
|
|
29
|
-
//
|
|
30
|
-
import {
|
|
50
|
+
// components/TodoApp.js
|
|
51
|
+
import { connect } from 'redux-vue';
|
|
31
52
|
|
|
32
|
-
const
|
|
33
|
-
|
|
53
|
+
const TodoApp = {
|
|
54
|
+
props: {
|
|
55
|
+
todos: { type: Array },
|
|
56
|
+
addTodo: { type: Function },
|
|
57
|
+
},
|
|
58
|
+
render(h) {
|
|
59
|
+
return (
|
|
60
|
+
<div>
|
|
61
|
+
<ul>{this.todos.map(t => <li>{t}</li>)}</ul>
|
|
62
|
+
<button onClick={() => this.addTodo('new item')}>Add</button>
|
|
63
|
+
</div>
|
|
64
|
+
);
|
|
65
|
+
},
|
|
34
66
|
};
|
|
35
67
|
|
|
36
|
-
const
|
|
37
|
-
switch(action.type){
|
|
38
|
-
case 'ADD_TODO':
|
|
39
|
-
return {
|
|
40
|
-
...state,
|
|
41
|
-
todos: [...state.todos, action.data.todo]
|
|
42
|
-
}
|
|
68
|
+
const mapStateToProps = state => ({ todos: state.todos });
|
|
43
69
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const AppStore = createStore(reducer);
|
|
70
|
+
const mapDispatchToProps = dispatch => ({
|
|
71
|
+
addTodo: todo => dispatch({ type: 'ADD_TODO', payload: todo }),
|
|
72
|
+
});
|
|
50
73
|
|
|
51
|
-
export default
|
|
74
|
+
export default connect(mapStateToProps, mapDispatchToProps)(TodoApp);
|
|
52
75
|
```
|
|
53
76
|
|
|
54
|
-
|
|
77
|
+
### Single-file components
|
|
78
|
+
|
|
55
79
|
```js
|
|
56
80
|
// components/App.js
|
|
57
|
-
|
|
58
81
|
import { connect } from 'redux-vue';
|
|
82
|
+
import Comp from './Comp.vue';
|
|
83
|
+
|
|
84
|
+
const mapStateToProps = state => ({ count: state.count });
|
|
85
|
+
const mapDispatchToProps = dispatch => ({
|
|
86
|
+
increment: () => dispatch({ type: 'INCREMENT' }),
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
export default connect(mapStateToProps, mapDispatchToProps)(Comp);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## API
|
|
95
|
+
|
|
96
|
+
### `connect([mapStateToProps], [mapDispatchToProps], [mergeProps])(Component)`
|
|
97
|
+
|
|
98
|
+
| Argument | Type | Description |
|
|
99
|
+
| --------------------------------------- | --------------------- | -------------------------------------------------------- |
|
|
100
|
+
| `mapStateToProps(state, ownAttrs)` | Function | Maps store state to props. Called on every store update. |
|
|
101
|
+
| `mapDispatchToProps(dispatch)` | Function | Maps dispatch calls to props. |
|
|
102
|
+
| `mergeProps(stateProps, dispatchProps)` | Function _(optional)_ | Combine or rename keys before they reach the child. |
|
|
103
|
+
|
|
104
|
+
**Pass-through props** — props not declared in the map functions are forwarded to
|
|
105
|
+
the wrapped component automatically.
|
|
106
|
+
|
|
107
|
+
**Slots** — slot content on the connected wrapper is forwarded to the inner component.
|
|
108
|
+
|
|
109
|
+
### `reduxStorePlugin`
|
|
110
|
+
|
|
111
|
+
A Vue plugin. Call `Vue.use(reduxStorePlugin)` once with `store` set on the root
|
|
112
|
+
instance. All descendant components will have `this.$store` available.
|
|
59
113
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## Examples
|
|
117
|
+
|
|
118
|
+
### `mergeProps`
|
|
119
|
+
|
|
120
|
+
```js
|
|
121
|
+
const mergeProps = (stateProps, dispatchProps) => ({
|
|
122
|
+
fullCount: stateProps.count * 2,
|
|
123
|
+
onAdd: dispatchProps.addTodo,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(App);
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Pass-through props
|
|
130
|
+
|
|
131
|
+
```html
|
|
132
|
+
<!-- nonMappedProp is not in mapStateToProps — it still reaches the wrapped component -->
|
|
133
|
+
<ConnectedApp nonMappedProp="Foo" />
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Slots
|
|
137
|
+
|
|
138
|
+
```html
|
|
139
|
+
<ConnectedApp>
|
|
140
|
+
<span>This slot content is forwarded to the inner component</span>
|
|
141
|
+
</ConnectedApp>
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## Store example
|
|
147
|
+
|
|
148
|
+
```js
|
|
149
|
+
// store.js
|
|
150
|
+
import { createStore } from 'redux';
|
|
151
|
+
|
|
152
|
+
const initialState = { todos: [] };
|
|
153
|
+
|
|
154
|
+
const reducer = (state = initialState, action) => {
|
|
155
|
+
switch (action.type) {
|
|
156
|
+
case 'ADD_TODO':
|
|
157
|
+
return { ...state, todos: [...state.todos, action.payload] };
|
|
158
|
+
default:
|
|
159
|
+
return state;
|
|
160
|
+
}
|
|
89
161
|
};
|
|
90
162
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
function mapActionToProps(dispatch) {
|
|
98
|
-
return {
|
|
99
|
-
addTodo(todo) {
|
|
100
|
-
dispatch({
|
|
101
|
-
type: 'ADD_TODO',
|
|
102
|
-
data: { todo }
|
|
103
|
-
})
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export default connect(mapStateToProps, mapActionToProps)(App);
|
|
163
|
+
export default createStore(reducer);
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## Development
|
|
109
169
|
|
|
170
|
+
```bash
|
|
171
|
+
git clone https://github.com/nadimtuhin/redux-vue.git
|
|
172
|
+
cd redux-vue
|
|
173
|
+
npm install
|
|
174
|
+
npm test
|
|
110
175
|
```
|
|
176
|
+
|
|
177
|
+
Tests live in `src/*.spec.js` and use Mocha. See [CONTRIBUTING.md](CONTRIBUTING.md)
|
|
178
|
+
for contribution guidelines.
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## License
|
|
183
|
+
|
|
184
|
+
[MIT](LICENSE) © Nadim Tuhin
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "redux-vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Vue Redux binding higher order component",
|
|
5
5
|
"author": "Nadim Tuhin",
|
|
6
6
|
"repository": {
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
"url": "https://github.com/nadimtuhin/redux-vue.git"
|
|
9
9
|
},
|
|
10
10
|
"bugs": "https://github.com/nadimtuhin/redux-vue/issues",
|
|
11
|
-
"homepage": "
|
|
11
|
+
"homepage": "https://github.com/nadimtuhin/redux-vue#readme",
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"main": "lib/index.js",
|
|
14
14
|
"scripts": {
|
|
15
|
-
"test": "mocha \"./src/**/*.spec.js\" --
|
|
15
|
+
"test": "mocha \"./src/**/*.spec.js\" --require @babel/register",
|
|
16
16
|
"test:watch": "npm test -- --watch",
|
|
17
17
|
"compile": "babel -d lib/ src/",
|
|
18
18
|
"prepublish": "npm run compile"
|
|
@@ -26,10 +26,11 @@
|
|
|
26
26
|
"immutable"
|
|
27
27
|
],
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"babel
|
|
30
|
-
"babel
|
|
31
|
-
"babel
|
|
29
|
+
"@babel/core": "^8.0.1",
|
|
30
|
+
"@babel/preset-env": "^8.0.2",
|
|
31
|
+
"@babel/register": "^8.0.1",
|
|
32
32
|
"expect": "^1.20.2",
|
|
33
|
-
"mocha": "^
|
|
33
|
+
"mocha": "^11.7.6",
|
|
34
|
+
"redux": "^5.0.1"
|
|
34
35
|
}
|
|
35
36
|
}
|
package/.npmignore
DELETED
package/lib/connect.js
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
|
8
|
-
|
|
9
|
-
exports.default = connect;
|
|
10
|
-
|
|
11
|
-
var _normalizeProps = require('./normalizeProps');
|
|
12
|
-
|
|
13
|
-
var _normalizeProps2 = _interopRequireDefault(_normalizeProps);
|
|
14
|
-
|
|
15
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
-
|
|
17
|
-
function noop() {}
|
|
18
|
-
|
|
19
|
-
function getStore(component) {
|
|
20
|
-
return component.$store;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function getAttrs(component) {
|
|
24
|
-
return component._self.$options._parentVnode.data.attrs;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function getStates(component, mapStateToProps) {
|
|
28
|
-
var store = getStore(component);
|
|
29
|
-
var attrs = getAttrs(component);
|
|
30
|
-
|
|
31
|
-
return mapStateToProps(store.getState(), attrs) || {};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function getActions(component, mapActionsToProps) {
|
|
35
|
-
var store = getStore(component);
|
|
36
|
-
|
|
37
|
-
return mapActionsToProps(store.dispatch, getAttrs.bind(null, component)) || {};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function getProps(component) {
|
|
41
|
-
var props = {};
|
|
42
|
-
var attrs = getAttrs(component);
|
|
43
|
-
var stateNames = component.vuaReduxStateNames;
|
|
44
|
-
var actionNames = component.vuaReduxActionNames;
|
|
45
|
-
|
|
46
|
-
for (var ii = 0; ii < stateNames.length; ii++) {
|
|
47
|
-
props[stateNames[ii]] = component[stateNames[ii]];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
for (var _ii = 0; _ii < actionNames.length; _ii++) {
|
|
51
|
-
props[actionNames[_ii]] = component[actionNames[_ii]];
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return _extends({}, props, attrs);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* 1. utilities are moved above because vue stores methods, states and props
|
|
59
|
-
* in the same namespace
|
|
60
|
-
* 2. actions are set while created
|
|
61
|
-
*/
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* @param mapStateToProps
|
|
65
|
-
* @param mapActionsToProps
|
|
66
|
-
* @returns Object
|
|
67
|
-
*/
|
|
68
|
-
function connect(mapStateToProps, mapActionsToProps) {
|
|
69
|
-
mapStateToProps = mapStateToProps || noop;
|
|
70
|
-
mapActionsToProps = mapActionsToProps || noop;
|
|
71
|
-
|
|
72
|
-
return function (children) {
|
|
73
|
-
|
|
74
|
-
/** @namespace children.collect */
|
|
75
|
-
if (children.collect) {
|
|
76
|
-
children.props = _extends({}, (0, _normalizeProps2.default)(children.props || {}), (0, _normalizeProps2.default)(children.collect || {}));
|
|
77
|
-
|
|
78
|
-
var msg = 'vua-redux: collect is deprecated, use props ' + ('in ' + (children.name || 'anonymous') + ' component');
|
|
79
|
-
|
|
80
|
-
console.warn(msg);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
name: 'ConnectVuaRedux-' + (children.name || 'children'),
|
|
85
|
-
|
|
86
|
-
render: function render(h) {
|
|
87
|
-
var props = getProps(this);
|
|
88
|
-
|
|
89
|
-
return h(children, { props: props });
|
|
90
|
-
},
|
|
91
|
-
data: function data() {
|
|
92
|
-
var state = getStates(this, mapStateToProps);
|
|
93
|
-
var actions = getActions(this, mapActionsToProps);
|
|
94
|
-
var stateNames = Object.keys(state);
|
|
95
|
-
var actionNames = Object.keys(actions);
|
|
96
|
-
|
|
97
|
-
return _extends({}, state, actions, {
|
|
98
|
-
vuaReduxStateNames: stateNames,
|
|
99
|
-
vuaReduxActionNames: actionNames
|
|
100
|
-
});
|
|
101
|
-
},
|
|
102
|
-
created: function created() {
|
|
103
|
-
var _this = this;
|
|
104
|
-
|
|
105
|
-
var store = getStore(this);
|
|
106
|
-
|
|
107
|
-
this.vuaReduxUnsubscribe = store.subscribe(function () {
|
|
108
|
-
var state = getStates(_this, mapStateToProps);
|
|
109
|
-
var stateNames = Object.keys(state);
|
|
110
|
-
_this.vuaReduxStateNames = stateNames;
|
|
111
|
-
|
|
112
|
-
for (var ii = 0; ii < stateNames.length; ii++) {
|
|
113
|
-
_this[stateNames[ii]] = state[stateNames[ii]];
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
},
|
|
117
|
-
beforeDestroy: function beforeDestroy() {
|
|
118
|
-
this.vuaReduxUnsubscribe();
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
};
|
|
122
|
-
}
|
package/lib/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.reduxStorePlugin = exports.connect = undefined;
|
|
7
|
-
|
|
8
|
-
var _connect2 = require('./connect');
|
|
9
|
-
|
|
10
|
-
var _connect3 = _interopRequireDefault(_connect2);
|
|
11
|
-
|
|
12
|
-
var _reduxStorePlugin2 = require('./reduxStorePlugin');
|
|
13
|
-
|
|
14
|
-
var _reduxStorePlugin3 = _interopRequireDefault(_reduxStorePlugin2);
|
|
15
|
-
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
|
-
exports.connect = _connect3.default;
|
|
19
|
-
exports.reduxStorePlugin = _reduxStorePlugin3.default;
|
package/lib/normalizeProps.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = normalizeProps;
|
|
7
|
-
|
|
8
|
-
var _isArray = require('lodash/isArray');
|
|
9
|
-
|
|
10
|
-
var _isArray2 = _interopRequireDefault(_isArray);
|
|
11
|
-
|
|
12
|
-
var _isPlainObject = require('lodash/isPlainObject');
|
|
13
|
-
|
|
14
|
-
var _isPlainObject2 = _interopRequireDefault(_isPlainObject);
|
|
15
|
-
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
|
-
// https://github.com/vuejs/vue/blob/dev/src/util/options.js
|
|
19
|
-
function normalizeProps(props) {
|
|
20
|
-
var i,
|
|
21
|
-
val,
|
|
22
|
-
normalizedProps = {};
|
|
23
|
-
|
|
24
|
-
if ((0, _isArray2.default)(props)) {
|
|
25
|
-
i = props.length;
|
|
26
|
-
while (i--) {
|
|
27
|
-
val = props[i];
|
|
28
|
-
if (typeof val === 'string') {
|
|
29
|
-
normalizedProps[val] = null;
|
|
30
|
-
} else if (val.name) {
|
|
31
|
-
normalizedProps[val.name] = val;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
} else if ((0, _isPlainObject2.default)(props)) {
|
|
35
|
-
var keys = Object.keys(props);
|
|
36
|
-
i = keys.length;
|
|
37
|
-
while (i--) {
|
|
38
|
-
var key = keys[i];
|
|
39
|
-
val = props[key];
|
|
40
|
-
normalizedProps[key] = props[key];
|
|
41
|
-
if (typeof val === 'function') {
|
|
42
|
-
normalizedProps[key] = { type: val };
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return normalizedProps;
|
|
48
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var _expect = require('expect');
|
|
4
|
-
|
|
5
|
-
var _expect2 = _interopRequireDefault(_expect);
|
|
6
|
-
|
|
7
|
-
var _normalizeProps = require('./normalizeProps');
|
|
8
|
-
|
|
9
|
-
var _normalizeProps2 = _interopRequireDefault(_normalizeProps);
|
|
10
|
-
|
|
11
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
-
|
|
13
|
-
describe('normalize props', function () {
|
|
14
|
-
it('should normalize array props', function () {
|
|
15
|
-
(0, _expect2.default)((0, _normalizeProps2.default)(['a', 'b'])).toEqual({ a: null, b: null });
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('should normalize object props', function () {
|
|
19
|
-
var props = { 'a': { type: String }, 'b': null };
|
|
20
|
-
(0, _expect2.default)((0, _normalizeProps2.default)(props)).toEqual(props);
|
|
21
|
-
});
|
|
22
|
-
});
|