Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
fix(wechat): 修复 onUnhandledRejection onThemeChange 生命周期不生效的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Darmody committed May 8, 2020
1 parent 3d3dbe5 commit e7a7556
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/remax-runtime/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@ module.exports = {
},
],
__REMAX_APP_ENTRY_INFO__: {},
__REMAX_APP_EVENTS__: ['onLaunch', 'onShow', 'onHide', 'onShareAppMessage', 'onPageNotFound', 'onError'],
__REMAX_APP_EVENTS__: [
'onLaunch',
'onShow',
'onHide',
'onShareAppMessage',
'onPageNotFound',
'onError',
'onUnhandledRejection',
'onThemeChange',
],
__REMAX_PAGE_EVENTS__: {
'/path/to/test/index': ['onShow'],
'/path/to/test/index2': [
Expand Down
14 changes: 14 additions & 0 deletions packages/remax-runtime/src/__tests__/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ describe('app', () => {
log.push('onPageNotFound');
}

onUnhandledRejection() {
log.push('onUnhandledRejection');
}

onThemeChange() {
log.push('onThemeChange');
}

render() {
return <React.Fragment>{this.props.children}</React.Fragment>;
}
Expand All @@ -46,6 +54,8 @@ describe('app', () => {
app.shareAppMessage();
app.pageNotFound();
app.error();
app.unhandledRejection();
app.themeChange();
app.hide();

expect(log).toEqual([
Expand All @@ -57,6 +67,8 @@ describe('app', () => {
'onPageNotFound',
'error',
'onError',
'onUnhandledRejection',
'onThemeChange',
'onHide',
]);
});
Expand Down Expand Up @@ -100,6 +112,8 @@ describe('app', () => {
app.pageNotFound();
app.shareAppMessage();
app.error();
app.unhandledRejection();
app.themeChange();
app.hide();

expect(log).toEqual(['launch', 'show', 'appEventShow', 'pageNotFound', 'shareAppMessage', 'error', 'hide']);
Expand Down
8 changes: 8 additions & 0 deletions packages/remax-runtime/src/__tests__/helpers/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ class App {
this.config.onError('error');
}

themeChange() {
this.config.onThemeChange();
}

unhandledRejection() {
this.config.onUnhandledRejection();
}

pageNotFound() {
this.config.onPageNotFound({
path: 'path',
Expand Down
10 changes: 10 additions & 0 deletions packages/remax-runtime/src/createAppConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ export default function createAppConfig(this: any, App: any) {
onPageNotFound(options: any) {
return this.callLifecycle(AppLifecycle.pageNotFound, options);
},

// 微信
onUnhandledRejection(options: any) {
return this.callLifecycle(AppLifecycle.unhandledRejection, options);
},

// 微信
onThemeChange(options: any) {
return this.callLifecycle(AppLifecycle.themeChange, options);
},
};

appEvents().forEach(eventName => {
Expand Down
2 changes: 2 additions & 0 deletions packages/remax-runtime/src/lifecycle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export enum AppLifecycle {
error = 'error',
shareAppMessage = 'shareAppMessage',
pageNotFound = 'pageNotFound',
unhandledRejection = 'unhandledRejection',
themeChange = 'themeChange',
}

export function lifeCycleName(name: string): Lifecycle {
Expand Down

0 comments on commit e7a7556

Please sign in to comment.