Skip to content

Commit

Permalink
Merge branch 'master' into immutable-store
Browse files Browse the repository at this point in the history
  • Loading branch information
okjulian committed May 16, 2017
2 parents de70144 + 2581be1 commit 9a9aced
Show file tree
Hide file tree
Showing 38 changed files with 126 additions and 772 deletions.
1 change: 0 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"react"
],
"plugins": [
"flow-react-proptypes",
"transform-object-rest-spread",
"transform-class-properties",
"transform-flow-strip-types"
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Redux Offline specific ignores
lib/

# Logs
logs
*.log
Expand Down
52 changes: 28 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,31 @@ Redux Offline is very, very new. If you find a bug, good job for being an early
npm install --save redux-offline
```

##### 2. Replace [redux createStore](http://redux.js.org/docs/api/createStore.html) with createOfflineStore
##### 2. Add the `offline` [store enhancer](http://redux.js.org/docs/Glossary.html#store-enhancer) with `compose`
```diff

- import { applyMiddleware, createStore } from 'redux';
+ import { applyMiddleware } from 'redux';
+ import { createOfflineStore } from 'redux-offline';
+ import { applyMiddleware, createStore, compose } from 'redux';
+ import { offline } from 'redux-offline';
+ import offlineConfig from 'redux-offline/lib/defaults';

// ...

- const store = createStore(
+ const store = createOfflineStore(
const store = createStore(
reducer,
preloadedState,
applyMiddleware(middleware),
+ offlineConfig
- applyMiddleware(middleware)
+ compose(
+ applyMiddleware(middleware),
+ offline(offlineConfig)
+ )
);
```

See [Configuration](#configuration) for overriding default configurations.

Looking for `createOfflineStore` from redux-offline 1.x? See migration instructions in the [2.0.0 release notes](https://github.com/jevakallio/redux-offline/releases/tag/v2.0.0).

##### 3. Decorate actions with offline metadata

```js
Expand Down Expand Up @@ -208,7 +212,7 @@ const ordersReducer = (state, action) {
The last part of the offline metadata is `meta.offline.effect`. This property can contain anything, and will be passed as-is to the effects reconciler.
The **effects reconciler** is a function that you pass to `createOfflineStore` configuration, whose responsibility it is to take the effect payload, send it over the network, and return a Promise that resolves if sending was successful or rejects if the sending failed. The method is passed the full action as a second parameter:
The **effects reconciler** is a function that you pass to offline enhancer configuration, whose responsibility it is to take the effect payload, send it over the network, and return a Promise that resolves if sending was successful or rejects if the sending failed. The method is passed the full action as a second parameter:
```js
type EffectsReconciler = (effect: any, action: OfflineAction) => Promise<any>
Expand Down Expand Up @@ -300,45 +304,44 @@ export type Config = {
};
```
#### Passing configuration to createOfflineStore
The `createOfflineStore` store creator takes the [configuration object](#configuration-object) as a final parameter:
#### Passing configuration to the enhancer
The `offline` store enhancer takes the [configuration object](#configuration-object) as a final parameter:
```diff
+ import { createOfflineStore } from 'redux-offline';
+ import { offline } from 'redux-offline';
+ import defaultConfig from 'redux-offline/lib/defaults';
+
- const store = createStore(
+ const store = createOfflineStore(

const store = createStore(
reducer,
preloadedState,
middleware,
+ defaultConfig
- middleware
+ compose(middleware, offline(defaultConfig))
);
```
#### Overriding default properties
You can override any individual property in the default configuration:
```diff
import { createOfflineStore } from 'redux-offline';
import { offline } from 'redux-offline';
import defaultConfig from 'redux-offline/lib/defaults';

const customConfig = {
...defaultConfig,
effect: (effect, _action) => Api.send(effect)
}

const store = createOfflineStore(
const store = createStore(
reducer,
preloadedState,
middleware,
+ customConfig
- middleware
+ compose(middleware, offline(customConfig))
);
```
#### Only import what you need
The reason for default config is defined as a separate import is, that it pulls in the [redux-persist](https://github.com/rt2zz/redux-persist) dependency and a limited, but non-negligible amount of library code. If you want to minimize your bundle size, you'll want to avoid importing any code you don't use, and bring in only the pieces you need:
```diff
import { createOfflineStore } from 'redux-offline';
import { offline } from 'redux-offline';
import batch from 'redux-offline/lib/defaults/batch';
import retry from 'redux-offline/lib/defaults/retry';
import discard from 'redux-offline/lib/defaults/discard';
Expand All @@ -351,11 +354,12 @@ const myConfig = {
persist: (store) => MyCustomPersistence.persist(store)
};

const store = createOfflineStore(
const store = createStore(
reducer,
preloadedState,
middleware,
+ myConfig
- middleware
+ compose(middleware, offline(myConfig))
myConfig
);
```
Expand Down
42 changes: 0 additions & 42 deletions lib/actions.js

This file was deleted.

24 changes: 0 additions & 24 deletions lib/config.js

This file was deleted.

10 changes: 0 additions & 10 deletions lib/constants.js

This file was deleted.

14 changes: 0 additions & 14 deletions lib/defaults/batch.js

This file was deleted.

30 changes: 0 additions & 30 deletions lib/defaults/detectNetwork.js

This file was deleted.

25 changes: 0 additions & 25 deletions lib/defaults/detectNetwork.native.js

This file was deleted.

22 changes: 0 additions & 22 deletions lib/defaults/discard.js

This file was deleted.

45 changes: 0 additions & 45 deletions lib/defaults/effect.js

This file was deleted.

0 comments on commit 9a9aced

Please sign in to comment.