Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
node_modules
npm-debug.log
.DS_Store
dist
lib
coverage
*.tgz
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,20 @@ For Angular 2 see [ng2-redux](https://github.com/wbuchwalter/ng2-redux).


## Installation

#### npm
```js
npm install --save ng-redux
```
#### bower
```js
bower install --save ng-redux
```

Add the following script tag to your html:

```html
<script src="bower_components/ng-redux/dist/ng-redux.js"></script>
```

## Quick Start

Expand Down
23 changes: 23 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "ng-redux",
"version": "3.0.2",
"homepage": "http://github.com/wbuchwalter/ng-redux",
"authors": [
"William Buchwalter <wbuchwalter@gmail.com> (http://github.com/wbuchwalter)"
],
"description": "Redux bindings for Angular.js",
"main": "./dist/ng-redux.js",
"moduleType": [],
"keywords": [
"angular",
"redux"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
]
}
1 change: 1 addition & 0 deletions dist/ng-redux.js

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "./lib/index.js",
"scripts": {
"build": "rm -rf lib && `npm bin`/babel src --out-dir lib",
"dist": "npm run build && ./node_modules/.bin/webpack --optimize-minimize lib/index.js dist/ng-redux.js",
"test": "mocha --compilers js:babel/register --recursive"
},
"repository": {
Expand All @@ -31,7 +32,11 @@
},
"dependencies": {
"invariant": "^2.1.0",
"lodash": "^3.10.1",
"lodash.assign": "^3.2.0",
"lodash.isarray": "^3.0.4",
"lodash.isfunction": "^3.0.6",
"lodash.isobject": "^3.0.2",
"lodash.isplainobject": "^3.2.0",
"redux": "^3.0.0"
}
}
20 changes: 12 additions & 8 deletions src/components/connector.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import shallowEqual from '../utils/shallowEqual';
import wrapActionCreators from '../utils/wrapActionCreators';
import invariant from 'invariant';
import _ from 'lodash';

import isPlainObject from 'lodash.isplainobject';
import isFunction from 'lodash.isfunction';
import isObject from 'lodash.isobject';
import assign from 'lodash.assign';

const defaultMapStateToTarget = () => ({});
const defaultMapDispatchToTarget = dispatch => ({dispatch});
Expand All @@ -11,17 +15,17 @@ export default function Connector(store) {

const finalMapStateToTarget = mapStateToTarget || defaultMapStateToTarget;

const finalMapDispatchToTarget = _.isPlainObject(mapDispatchToTarget) ?
const finalMapDispatchToTarget = isPlainObject(mapDispatchToTarget) ?
wrapActionCreators(mapDispatchToTarget) :
mapDispatchToTarget || defaultMapDispatchToTarget;

invariant(
_.isFunction(finalMapStateToTarget),
isFunction(finalMapStateToTarget),
'mapStateToTarget must be a Function. Instead received $s.', finalMapStateToTarget
);

invariant(
_.isPlainObject(finalMapDispatchToTarget) || _.isFunction(finalMapDispatchToTarget),
isPlainObject(finalMapDispatchToTarget) || isFunction(finalMapDispatchToTarget),
'mapDispatchToTarget must be a plain Object or a Function. Instead received $s.', finalMapDispatchToTarget
);

Expand All @@ -32,7 +36,7 @@ export default function Connector(store) {
return (target) => {

invariant(
_.isFunction(target) || _.isObject(target),
isFunction(target) || isObject(target),
'The target parameter passed to connect must be a Function or a object.'
);

Expand All @@ -53,18 +57,18 @@ export default function Connector(store) {
}

function updateTarget(target, StateSlice, dispatch) {
if(_.isFunction(target)) {
if(isFunction(target)) {
target(StateSlice, dispatch);
} else {
_.assign(target, StateSlice, dispatch);
assign(target, StateSlice, dispatch);
}
}

function getStateSlice(state, mapStateToScope) {
const slice = mapStateToScope(state);

invariant(
_.isPlainObject(slice),
isPlainObject(slice),
'`mapStateToScope` must return an object. Instead received %s.',
slice
);
Expand Down
8 changes: 5 additions & 3 deletions src/components/ngRedux.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import Connector from './connector';
import invariant from 'invariant';
import {createStore, applyMiddleware, compose} from 'redux';
import digestMiddleware from './digestMiddleware';
import _ from 'lodash';

import isArray from 'lodash.isarray';
import isFunction from 'lodash.isfunction';

export default function ngReduxProvider() {
let _reducer = undefined;
Expand All @@ -11,13 +13,13 @@ export default function ngReduxProvider() {

this.createStoreWith = (reducer, middlewares, storeEnhancers) => {
invariant(
_.isFunction(reducer),
isFunction(reducer),
'The reducer parameter passed to createStoreWith must be a Function. Instead received %s.',
typeof reducer
);

invariant(
!storeEnhancers || _.isArray(storeEnhancers),
!storeEnhancers || isArray(storeEnhancers),
'The storeEnhancers parameter passed to createStoreWith must be an Array. Instead received %s.',
typeof storeEnhancers
);
Expand Down
6 changes: 3 additions & 3 deletions test/components/connector.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import expect from 'expect';
let sinon = require('sinon');
import { createStore } from 'redux';
import Connector from '../../src/components/connector';
import _ from 'lodash';
import isFunction from 'lodash.isfunction';

describe('Connector', () => {
let store;
Expand Down Expand Up @@ -70,8 +70,8 @@ describe('Connector', () => {

it('Should extend target (object) with actionCreators', () => {
connect(() => ({}), { ac1: () => { }, ac2: () => { } })(targetObj);
expect(_.isFunction(targetObj.ac1)).toBe(true);
expect(_.isFunction(targetObj.ac2)).toBe(true);
expect(isFunction(targetObj.ac1)).toBe(true);
expect(isFunction(targetObj.ac2)).toBe(true);
});

it('Should return an unsubscribing function', () => {
Expand Down