react-native-offline
Advanced tools
Comparing version 4.1.2 to 4.1.3
{ | ||
"name": "react-native-offline", | ||
"version": "4.1.2", | ||
"version": "4.1.3", | ||
"description": "Handy toolbelt to deal with offline mode in React Native applications. Cross-platform, provides a smooth redux integration.", | ||
@@ -76,2 +76,5 @@ "main": "./src/index.js", | ||
}, | ||
"peerDependencies": { | ||
"redux":"4.x" | ||
}, | ||
"jest": { | ||
@@ -78,0 +81,0 @@ "collectCoverage": true, |
# react-native-offline | ||
[![All Contributors](https://img.shields.io/badge/all_contributors-29-orange.svg?style=flat-square)](#contributors) | ||
[![All Contributors](https://img.shields.io/badge/all_contributors-30-orange.svg?style=flat-square)](#contributors) | ||
[![CircleCI](https://circleci.com/gh/rgommezz/react-native-offline.svg?style=shield)](https://circleci.com/gh/rgommezz/react-native-offline) [![npm version](https://badge.fury.io/js/react-native-offline.svg)](https://badge.fury.io/js/react-native-offline) [![Coverage Status](https://coveralls.io/repos/github/rauliyohmc/react-native-offline/badge.svg?branch=master)](https://coveralls.io/github/rauliyohmc/react-native-offline?branch=master) | ||
@@ -69,6 +69,6 @@ [![npm](https://img.shields.io/npm/dm/react-native-offline.svg)]() | ||
[![issuehunt-image](https://github.com/BoostIO/issuehunt-materials/blob/master/issuehunt-badge@1x.png?raw=true)](https://issuehunt.io/repos/86369462) | ||
[![issuehunt-image](https://camo.githubusercontent.com/f5f88939f6c627454b7c5d0eaef9f7cc40cc9586/68747470733a2f2f697373756568756e742e696f2f7374617469632f656d6265642f697373756568756e742d627574746f6e2d76312e737667)](https://issuehunt.io/repos/86369462) | ||
## Installation | ||
This library supports React Native v0.55 or higher. | ||
This library supports React Native v0.55 or higher. You also need to have `react-redux` version 6.x.x installed. | ||
``` | ||
@@ -247,3 +247,3 @@ $ yarn add react-native-offline | ||
fork(saga2), | ||
fork(networkSaga, { checkConnectionInterval: 20000 }), | ||
fork(networkSaga, { pingInterval: 20000 }), | ||
]); | ||
@@ -466,3 +466,3 @@ } | ||
#### How to orchestrate Redux to dispatch `CONNECTION_CHANGE` as the first action when the app starts up | ||
The solution involves using some local state in your top most component and tweaking the `configureStore` function a bit, so that it can notify your root React component to render the whole application when the required initialisation has taken place. In this case, by initialisation, we are talking about rehydrating the store from disk and detecting initial internet connection. | ||
The solution assumes you are using Redux Persist v5.x and involves using some local state in your top most component and tweaking the `configureStore` function a bit, so that it can notify your root React component to render the whole application when the required initialisation has taken place. In this case, by initialisation, we are talking about rehydrating the store from disk and detecting initial internet connection. | ||
@@ -475,5 +475,4 @@ As you can see in the snippets below, we create the `store` instance as usual and return it in our `configureStore` function. The only difference is that the function is still _alive_ and will invoke the callback as soon as 2 actions are dispatched into the store (in order): | ||
// configureStore.js | ||
import { AsyncStorage, Platform, NetInfo } from 'react-native'; | ||
import { createStore, applyMiddleware, compose } from 'redux'; | ||
import { persistStore, autoRehydrate } from 'redux-persist'; | ||
import { createStore, applyMiddleware } from 'redux'; | ||
import { persistStore } from 'redux-persist'; | ||
import { createNetworkMiddleware, offlineActionTypes, checkInternetConnection } from 'react-native-offline'; | ||
@@ -485,28 +484,14 @@ import rootReducer from '../reducers'; | ||
export default function configureStore(callback) { | ||
const store = createStore( | ||
rootReducer, | ||
undefined, | ||
compose( | ||
applyMiddleware(networkMiddleware), | ||
autoRehydrate(), | ||
), | ||
); | ||
const store = createStore(rootReducer, applyMiddleware(networkMiddleware)); | ||
// https://github.com/rt2zz/redux-persist#persiststorestore-config-callback | ||
persistStore( | ||
store, | ||
{ | ||
storage: AsyncStorage, | ||
debounce: 500, | ||
}, | ||
() => { | ||
// After rehydration completes, we detect initial connection | ||
checkInternetConnection().then(isConnected => { | ||
store.dispatch({ | ||
type: offlineActionTypes.CONNECTION_CHANGE, | ||
payload: isConnected, | ||
}); | ||
callback(); // Notify our root component we are good to go, so that we can render our app | ||
persistStore(store, null, () => { | ||
// After rehydration completes, we detect initial connection | ||
checkInternetConnection().then(isConnected => { | ||
store.dispatch({ | ||
type: offlineActionTypes.CONNECTION_CHANGE, | ||
payload: isConnected, | ||
}); | ||
}, | ||
); | ||
callback(); // Notify our root component we are good to go, so that we can render our app | ||
}); | ||
}); | ||
@@ -691,5 +676,5 @@ return store; | ||
| [<img src="https://avatars2.githubusercontent.com/u/5106466?v=4" width="100px;"/><br /><sub><b>MichaΕ PierzchaΕa</b></sub>](https://buymeacoff.ee/thymikee)<br />[π»](https://github.com/rgommezz/react-native-offline/commits?author=thymikee "Code") | [<img src="https://avatars3.githubusercontent.com/u/119142?v=4" width="100px;"/><br /><sub><b>Ian Graham</b></sub>](https://github.com/imartingraham)<br />[π»](https://github.com/rgommezz/react-native-offline/commits?author=imartingraham "Code") | [<img src="https://avatars2.githubusercontent.com/u/1244867?v=4" width="100px;"/><br /><sub><b>Petter Samuelsen</b></sub>](http://www.pettersamuelsen.com)<br />[π»](https://github.com/rgommezz/react-native-offline/commits?author=pettersamuelsen "Code") | [<img src="https://avatars1.githubusercontent.com/u/5339061?v=4" width="100px;"/><br /><sub><b>Lukas Kurucz</b></sub>](https://github.com/usrbowe)<br />[π»](https://github.com/rgommezz/react-native-offline/commits?author=usrbowe "Code") | [<img src="https://avatars1.githubusercontent.com/u/18237132?v=4" width="100px;"/><br /><sub><b>Norris Oduro</b></sub>](https://twitter.com/norris1z)<br />[π»](https://github.com/rgommezz/react-native-offline/commits?author=Norris1z "Code") | [<img src="https://avatars3.githubusercontent.com/u/43637878?v=4" width="100px;"/><br /><sub><b>Richard Tan</b></sub>](https://github.com/richardtks)<br />[π€](#ideas-richardtks "Ideas, Planning, & Feedback") | [<img src="https://avatars3.githubusercontent.com/u/17765105?v=4" width="100px;"/><br /><sub><b>Oleg Kupriianov</b></sub>](https://twitter.com/tysh_pysh)<br />[π»](https://github.com/rgommezz/react-native-offline/commits?author=Jimbomaniak "Code") | | ||
| [<img src="https://avatars1.githubusercontent.com/u/11155505?v=4" width="100px;"/><br /><sub><b>reilem</b></sub>](https://github.com/reilem)<br />[π€](#ideas-reilem "Ideas, Planning, & Feedback") | | ||
| [<img src="https://avatars1.githubusercontent.com/u/11155505?v=4" width="100px;"/><br /><sub><b>reilem</b></sub>](https://github.com/reilem)<br />[π€](#ideas-reilem "Ideas, Planning, & Feedback") | [<img src="https://avatars1.githubusercontent.com/u/8154741?v=4" width="100px;"/><br /><sub><b>Josephine Wright</b></sub>](https://github.com/jozr)<br />[π](https://github.com/rgommezz/react-native-offline/commits?author=jozr "Documentation") | | ||
<!-- ALL-CONTRIBUTORS-LIST:END --> | ||
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome! |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67930
4
675