Skip to content

Commit

Permalink
fix(okam-core): fix baidu swan app custom component event object argu…
Browse files Browse the repository at this point in the history
…ment
  • Loading branch information
wuhy committed Dec 5, 2018
1 parent 98c3538 commit 9f82138
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/okam-core/src/base/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ export default {
* @param {Object} event the event object
*/
__handlerProxy(event) {
this.__beforeEventProxy && (event = this.__beforeEventProxy(event));

// get event dataSet
const data = event.currentTarget.dataset;
const eventType = event.type;
Expand Down
11 changes: 10 additions & 1 deletion packages/okam-core/src/swan/Component.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/**
* @file Create swan component instance
* Notice: Using swan custom component, suggest swan-core version `>=1.12`
* @author [email protected]
*/

'use strict';

import {createComponent} from '../helper/factory';
import {normalizeComponent} from '../helper/component';
import {normalizeEventArgs} from './helper/triggerEvent';
import {normalizeEventArgs, fixEventObject} from './helper/triggerEvent';
import componentBase from '../base/component';

/**
Expand All @@ -20,6 +21,14 @@ componentBase.methods.__beforeEmit = function (args) {
return normalizeEventArgs(this, args);
};

/**
* Fix swan 1.12 event arguments upgrade
*
* @param {Object} event the event object
* @return {Object} the new event object
*/
componentBase.methods.__beforeEventProxy = fixEventObject;

/**
* Create component instance
*
Expand Down
9 changes: 9 additions & 0 deletions packages/okam-core/src/swan/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@

import {createPage} from '../helper/factory';
import {normalizePage} from '../helper/page';
import {fixEventObject} from './helper/triggerEvent';
import pageBase from '../base/page';

/**
* Fix swan 1.12 event arguments upgrade
*
* @param {Object} event the event object
* @return {Object} the new event object
*/
pageBase.__beforeEventProxy = fixEventObject;

/**
* Create the page instance
*
Expand Down
17 changes: 17 additions & 0 deletions packages/okam-core/src/swan/helper/triggerEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,20 @@ export function normalizeEventArgs(component, args) {

return args;
}

/**
* Fix event object argument
*
* @param {Object} event the event object to fix
* @return {Object}
*/
export function fixEventObject(event) {
let detail = event && event.detail;
// fix 1.12.x event object argument upgrade which to make the event object
// structure like weixin
if (detail && detail.currentTarget && detail.target && detail.type) {
return detail;
}

return event;
}

0 comments on commit 9f82138

Please sign in to comment.