Skip to content

Commit 29b7ea0

Browse files
authored
Merge pull request #55 from Soomgo-Mobile/feature/v10-telemetry
feat(Runtime): add callback options for update success and rollback
2 parents a4f0e0c + 0a99bc6 commit 29b7ea0

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

CodePush.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,11 @@ async function tryReportStatus(statusReport, retryOnAppResume) {
253253
const label = statusReport.package.label;
254254
if (statusReport.status === "DeploymentSucceeded") {
255255
log(`Reporting CodePush update success (${label})`);
256+
sharedCodePushOptions?.onUpdateSuccess(label);
256257
} else {
257258
log(`Reporting CodePush update rollback (${label})`);
258259
await NativeCodePush.setLatestRollbackInfo(statusReport.package.packageHash);
260+
sharedCodePushOptions?.onUpdateRollback(label);
259261
}
260262
}
261263

@@ -584,6 +586,10 @@ let CodePush;
584586
* setReleaseHistoryFetcher(releaseHistoryFetcherFunction: releaseHistoryFetcher | undefined): void,
585587
* updateChecker: updateChecker | undefined,
586588
* setUpdateChecker(updateCheckerFunction: updateChecker | undefined): void,
589+
* onUpdateSuccess: (label: string) => void | undefined,
590+
* setOnUpdateSuccess(onUpdateSuccessFunction: (label: string) => void | undefined): void,
591+
* onUpdateRollback: (label: string) => void | undefined,
592+
* setOnUpdateRollback(onUpdateRollbackFunction: (label: string) => void | undefined): void,
587593
* }}
588594
*/
589595
const sharedCodePushOptions = {
@@ -598,6 +604,18 @@ const sharedCodePushOptions = {
598604
if (typeof updateCheckerFunction !== 'function') throw new Error('Please pass a function to updateChecker');
599605
this.updateChecker = updateCheckerFunction;
600606
},
607+
onUpdateSuccess: undefined,
608+
setOnUpdateSuccess(onUpdateSuccessFunction) {
609+
if (!onUpdateSuccessFunction) return;
610+
if (typeof onUpdateSuccessFunction !== 'function') throw new Error('Please pass a function to onUpdateSuccess');
611+
this.onUpdateSuccess = onUpdateSuccessFunction;
612+
},
613+
onUpdateRollback: undefined,
614+
setOnUpdateRollback(onUpdateRollbackFunction) {
615+
if (!onUpdateRollbackFunction) return;
616+
if (typeof onUpdateRollbackFunction !== 'function') throw new Error('Please pass a function to onUpdateRollback');
617+
this.onUpdateRollback = onUpdateRollbackFunction;
618+
},
601619
}
602620

603621
function codePushify(options = {}) {
@@ -627,6 +645,10 @@ function codePushify(options = {}) {
627645
sharedCodePushOptions.setReleaseHistoryFetcher(options.releaseHistoryFetcher);
628646
sharedCodePushOptions.setUpdateChecker(options.updateChecker);
629647

648+
// set telemetry callbacks
649+
sharedCodePushOptions.setOnUpdateSuccess(options.onUpdateSuccess);
650+
sharedCodePushOptions.setOnUpdateRollback(options.onUpdateRollback);
651+
630652
const decorator = (RootComponent) => {
631653
class CodePushComponent extends React.Component {
632654
constructor(props) {

typings/react-native-code-push.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ export interface CodePushOptions extends SyncOptions {
7373
* @deprecated It will be removed in the next major version. Please migrate to `releaseHistoryFetcher`.
7474
*/
7575
updateChecker?: (updateRequest: UpdateCheckRequest) => Promise<{ update_info: UpdateCheckResponse }>;
76+
/**
77+
* Callback function that is called when the update installation succeeds.
78+
*/
79+
onUpdateSuccess?: (label: string) => void;
80+
/**
81+
* Callback function that is called when the update rolled back.
82+
*/
83+
onUpdateRollback?: (label: string) => void;
7684
}
7785

7886
export interface DownloadProgress {

0 commit comments

Comments
 (0)