Skip to content

Commit 0dfccc4

Browse files
committed
Merge branch 'master' of http://github.com/wbuchwalter/ng-redux
2 parents d7f649a + b351052 commit 0dfccc4

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

README.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
# ng-redux
22
Angular bindings for [Redux](https://github.com/gaearon/redux).
33

4-
##Warning: The API is unstable and subject to breaking changes until Redux@1.0.0 is released.
4+
#####Warning: The API is unstable and subject to breaking changes until Redux@1.0.0 is released.
55

6-
![Travis](https://travis-ci.org/wbuchwalter/ng-redux.svg?branch=master)
6+
[![build status](https://img.shields.io/travis/wbuchwalter/ng-redux/master.svg?style=flat-square)](https://travis-ci.org/wbuchwalter/ng-redux)
7+
[![npm version](https://img.shields.io/npm/v/ng-redux.svg?style=flat-square)](https://www.npmjs.com/package/ng-redux)
78

89
## Overview
910

1011
ngRedux lets you easily connect your angular components with Redux.
1112
the API is straightforward:
1213

1314
```JS
14-
$ngRedux.connect(selector, callback);
15+
$ngRedux.connect(selector, callback, disableCaching = false);
1516
//OR
16-
$ngRedux.connect([selector1, selector2, ...], callback);
17+
$ngRedux.connect([selector1, selector2, ...], callback, disableCaching = false);
1718
```
1819

1920
Where selector is a function taking for single argument the entire redux Store's state (a plain JS object) and returns another object, which is the slice of the state that your component is interested in.
@@ -28,6 +29,9 @@ If you haven't, check out [reselect](https://github.com/faassen/reselect), an aw
2829

2930
This returned object will be passed as argument to the callback provided whenever the state changes.
3031
ngRedux checks for shallow equality of the state's selected slice whenever the Store is updated, and will call the callback only if there is a change.
32+
##### Important: It is assumed that you never mutate your states, if you do mutate them, ng-redux will not execute the callback properly.
33+
See [Redux's doc](http://gaearon.github.io/redux/docs/basics/Reducers.html) to understand why you should not mutate your states.
34+
If you have a good reason to mutate your states, you can still [disable caching](#Disable-caching) altogether.
3135

3236

3337
## Getting Started
@@ -47,7 +51,7 @@ angular.module('app', ['ngRedux'])
4751
});
4852
```
4953

50-
### Usage
54+
#### Usage
5155
```JS
5256
export default function todoLoader() {
5357
return {
@@ -70,7 +74,7 @@ class TodoLoaderController {
7074
}
7175
```
7276

73-
### Note: The callback provided to ```connect``` will be called once directly after creation to allow initialization of your component states
77+
##### Note: The callback provided to ```connect``` will be called once directly after creation to allow initialization of your component states
7478

7579

7680

@@ -110,14 +114,22 @@ destroy() {
110114
```
111115

112116

113-
### Accessing Redux' Store
117+
#### Accessing Redux' Store
114118
You don't need to create another service to get hold of Redux's store (although you can).
115119
You can access the store via ```$ngRedux.getStore()```:
116120

117121
```JS
118122
redux.bindActionCreators(actionCreator, $ngRedux.getStore().dispatch);
119123
```
120124

125+
#### Disabling caching
126+
Each time Redux's Store update, ng-redux will check if the slices specified via 'selectors' have changed, and if so will execute the provided callback.
127+
You can disable this behaviour, and force the callback to be executed even if the slices didn't change by setting ```disableCaching``` to true:
128+
129+
```JS
130+
reduxConnector.connect(state => state.todos, todos => this.todos = todos, true);
131+
```
132+
121133

122134
### Example:
123135
An example can be found here (in TypeScript): [tsRedux](https://github.com/wbuchwalter/tsRedux/blob/master/src/components/regionLister.ts).

0 commit comments

Comments
 (0)