-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(okam-core): change custom component trigger event normalize …
…using beforeEmit hook and only for swan
- Loading branch information
Showing
4 changed files
with
81 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* @file Component triggerEvent helper | ||
* @author [email protected] | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/** | ||
* Normalize event arguments to fix the native swan framework bug | ||
* | ||
* @param {Component} component current component instance | ||
* @param {Object} args the event args to normalize | ||
* @return {Object} | ||
*/ | ||
export function normalizeEventArgs(component, args) { | ||
let eventData = args[1]; | ||
if (eventData.currentTarget && eventData.target) { | ||
return args; | ||
} | ||
|
||
let propData = component.properties; | ||
let dataset = {}; | ||
propData && Object.keys(propData).forEach(k => { | ||
if (/^data\w+$/.test(k)) { | ||
let dataKey = k.replace( | ||
/^data(\w)/, | ||
(match, char) => char.toLowerCase() | ||
); | ||
dataset[dataKey] = propData[k]; | ||
} | ||
}); | ||
|
||
let eventObj = { | ||
type: args[0], | ||
currentTarget: { | ||
dataset, | ||
id: component.id | ||
}, | ||
target: { | ||
dataset, | ||
id: component.id | ||
}, | ||
detail: eventData | ||
}; | ||
args[1] = eventObj; | ||
|
||
return args; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters