Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 4fe0f87

Browse files
committed
update docs
2 parents 79381eb + 88d325d commit 4fe0f87

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -697,14 +697,12 @@ The following sections describe the shape and behavior of these APIs in detail:
697697
698698
### JavaScript API Reference
699699
700-
When you require `react-native-code-push`, the module object provides the following top-level methods:
700+
When you require `react-native-code-push`, the module object provides the following top-level methods in addition to the root-level [component decorator](#codepush):
701701
702702
* [allowRestart](#codepushallowrestart): Re-allows programmatic restarts to occur as a result of an update being installed, and optionally, immediately restarts the app if a pending update had attempted to restart the app while restarts were disallowed. This is an advanced API and is only necessary if your app explicitly disallowed restarts via the `disallowRestart` method.
703703
704704
* [checkForUpdate](#codepushcheckforupdate): Asks the CodePush service whether the configured app deployment has an update available.
705705
706-
* [codePushify](#codepushcodepushify): Returns a function that wraps a React component inside a "higher order" React component configured to call [`codePush.sync()`](#codepushsync) when it is mounted. This allows you to declaratively specify the behaviour of how and when your app checks for an update, downloads it and installs it.
707-
708706
* [disallowRestart](#codepushdisallowrestart): Temporarily disallows any programmatic restarts to occur as a result of a CodePush update being installed. This is an advanced API, and is useful when a component within your app (e.g. an onboarding process) needs to ensure that no end-user interruptions can occur during its lifetime.
709707
710708
* [getCurrentPackage](#codepushgetcurrentpackage): Retrieves the metadata about the currently installed update (e.g. description, installation time, size). *NOTE: As of `v1.10.3-beta` of the CodePush module, this method is deprecated in favor of [`getUpdateMetadata`](#codepushgetupdatemetadata)*.
@@ -720,11 +718,16 @@ When you require `react-native-code-push`, the module object provides the follow
720718
#### codePush
721719
722720
```javascript
721+
// Wrapper functions
723722
codePush(rootComponent: React.Component): React.Component;
724723
codePush(options: CodePushOptions)(rootComponent: React.Component): React.Component;
724+
725+
// Decorators; Requires ES7 support
726+
@codePush
727+
@codePush(options: CodePushOptions)
725728
```
726729
727-
Used as a decorator to wrap a React component inside a "higher order" React component that knows how to synchronize your app's JavaScript bundle and image assets with the latest release to the configured deployment when it is mounted. Internally, the wrapper component calls [`sync`](#codepushsync) inside its `componentDidMount` lifecycle handle, which in turns performs an update check, downloads the update if it exists and installs the update for you.
730+
Used to wrap a React component inside a "higher order" React component that knows how to synchronize your app's JavaScript bundle and image assets when it is mounted. Internally, the higher-order component calls [`sync`](#codepushsync) inside its `componentDidMount` lifecycle handle, which in turns performs an update check, downloads the update if it exists and installs the update for you.
728731
729732
This decorator provides support for letting you customize its behaviour to easily enable apps with different requirements. Below are some examples of ways you can use it (you can pick one or even use a combination):
730733
@@ -734,16 +737,16 @@ This decorator provides support for letting you customize its behaviour to easil
734737
// Fully silent update which keeps the app in
735738
// sync with the server, without ever
736739
// interrupting the end user
737-
@codePush
738740
class MyApp extends Component {}
741+
codePush(MyApp);
739742
```
740743
741744
2. **Silent sync everytime the app resumes**. Same as 1, except we check for updates, or apply an update if one exists every time the app returns to the foreground after being "backgrounded".
742745
743746
```javascript
744747
// Sync for updates everytime the app resumes.
745-
@codePush({ checkFrequency: codePush.CheckFrequency.ON_APP_RESUME, installMode: codePush.InstallMode.ON_NEXT_RESUME })
746748
class MyApp extends Component {}
749+
codePush({ checkFrequency: codePush.CheckFrequency.ON_APP_RESUME, installMode: codePush.InstallMode.ON_NEXT_RESUME })(MyApp);
747750
```
748751
749752
3. **Interactive**. When an update is available, prompt the end user for permission before downloading it, and then immediately apply the update. If an update was released using the `mandatory` flag, the end user would still be notified about the update, but they wouldn't have the choice to ignore it.
@@ -752,16 +755,15 @@ This decorator provides support for letting you customize its behaviour to easil
752755
// Active update, which lets the end user know
753756
// about each update, and displays it to them
754757
// immediately after downloading it
755-
@codePush({ updateDialog: true, installMode: codePush.InstallMode.IMMEDIATE })
756758
class MyApp extends Component {}
759+
codePush({ updateDialog: true, installMode: codePush.InstallMode.IMMEDIATE })(MyApp);
757760
```
758761
759762
4. **Log/display progress**. While the app is syncing with the server for updates, make use of the `codePushStatusDidChange` and/or `codePushDownloadDidProgress` event hooks to log down the different stages of this process, or even display a progress bar to the user.
760763
761764
```javascript
762765
// Make use of the event hooks to keep track of
763766
// the different stages of the sync process.
764-
@codePush
765767
class MyApp extends Component {
766768
codePushStatusDidChange(status) {
767769
switch(syncStatus) {
@@ -787,6 +789,7 @@ This decorator provides support for letting you customize its behaviour to easil
787789
console.log(progess.receivedBytes + " of " + progress.totalBytes + " received.");
788790
}
789791
}
792+
codePush(MyApp);
790793
```
791794
792795
##### CodePushOptions

0 commit comments

Comments
 (0)