-
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.
fix(okam-core): fix ant custom component event emit
- Loading branch information
Showing
10 changed files
with
123 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
/** | ||
* @file Create component instance | ||
* @file Create swan component instance | ||
* @author [email protected] | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import {createComponent} from './helper/factory'; | ||
import {normalizeComponent} from './helper/component'; | ||
import {normalizeEventArgs} from './helper/triggerEvent'; | ||
import {normalizeEventArgs} from './swan/triggerEvent'; | ||
import componentBase from './base/component'; | ||
|
||
/** | ||
|
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
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,56 @@ | ||
/** | ||
* @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.props; | ||
let dataset = {}; | ||
propData && Object.keys(propData).forEach(k => { | ||
if (/^data\-.+$/.test(k)) { | ||
let first = true; | ||
let dataKey = k.replace( | ||
/\-(\w)/g, | ||
(match, char) => { | ||
if (first) { | ||
first = false; | ||
return char.toLowerCase(); | ||
} | ||
return char.toUpperCase(); | ||
} | ||
); | ||
dataKey = dataKey.substr('data'.length); | ||
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
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 |
---|---|---|
@@ -1,13 +1,29 @@ | ||
/** | ||
* @file Component helper | ||
* @file Component normalizer helper | ||
* @author [email protected] | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import {normalizeProps} from './props'; | ||
import {normalizeMethods} from './methods'; | ||
|
||
/** | ||
* Normalize component props data using mini program syntax | ||
* | ||
* @param {Object} props the props data to normalize | ||
* @return {?Object} | ||
*/ | ||
function normalizeProps(props) { | ||
Object.keys(props).forEach(k => { | ||
let propValue = props[k]; | ||
if (propValue && propValue.default !== undefined) { | ||
propValue.value = propValue.default; | ||
delete propValue.default; | ||
} | ||
}); | ||
return props; | ||
} | ||
|
||
/** | ||
* Normalize the component or behavior attribute names to native | ||
* | ||
|
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/** | ||
* @file Component props helper | ||
* @file OKAM component props helper | ||
* @author [email protected] | ||
*/ | ||
|
||
|
@@ -69,21 +69,3 @@ export function normalizeOkamProps(props) { | |
}); | ||
return result; | ||
} | ||
|
||
/** | ||
* Normalize component props data using mini program syntax | ||
* | ||
* @param {Object} props the props data to normalize | ||
* @return {?Object} | ||
*/ | ||
export function normalizeProps(props) { | ||
Object.keys(props).forEach(k => { | ||
let propValue = props[k]; | ||
if (propValue && propValue.default !== undefined) { | ||
propValue.value = propValue.default; | ||
delete propValue.default; | ||
} | ||
}); | ||
return props; | ||
} | ||
|
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
File renamed without changes.