react-native-code-push-saga
v1.0.1
Published
Redux saga that handles synchronizing a React Native app with the CodePush service
Downloads
1,608
Readme
Redux Saga for CodePush
This module provides a "saga" for React Native apps that already use Redux and Redux Saga for modeling asynchronous behavior, and want to integrate code sychronization with the CodePush service via a simple, declarative solution.
Getting Started
If you haven't already, install and setup the React Native module for CodePush
Install the CodePush Redux Saga via NPM
npm i --save react-native-code-push-saga@latest
Within your app's main saga, import the saga module
import codePushSaga from "react-native-code-push-saga";
Spawn/fork an instance of the CodePush saga
yield spawn(codePushSaga);
And that's it! By default, your app will now synchronize with CodePush on start, resume, and any time you dispatch a SYNC
action to your Redux store. If you want to customize the "sync points" (e.g. on a timer interval), delay syncing after the initial app store installation, or modify the options that are used when a sync occurs, you can pass additional parameters to the saga when spawning/forking. The following example illustrate some of the possibilities:
// Disable syncing on resume, but synchronize
// with CodePush every 5 minutes.
yield spawn(codePushSaga, {
syncOnResume: false,
syncOnInterval: 5 * 60
});
// Don't disrupt the user with an update after
// initially installing the app, until either 10
// minutes have passed or when the "ONBOARDING_COMPLETE"
// action is dispatched.
yield spawn(codePushSaga, {
delayByInterval: 10 * 60,
delayByAction: "ONBOARDING_COMPLETE"
});
// Customize the install mode of updates
// to occur when the app next resumes.
yield spawn(codePushSaga, {
syncOptions: {
installMode: codePush.InstallMode.ON_NEXT_RESUME
}
});
// Synchronize with CodePush anytime
// a Redux action named "NAVIGATE_HOME" is dispatched.
yield spawn(codePushSaga, {
syncActionName: "NAVIGATE_HOME"
});
// Invoke a callback every time the sync status changes
// or show a status bar as the download progresses.
// You can find a list of status types at
// https://github.com/Microsoft/react-native-code-push#syncstatus.
yield spawn(codePushSaga, {
codePushStatusDidChange: this.codePushStatusDidChange,
codePushDownloadDidProgress: this.codePushDownloadDidProgress,
});