diff --git a/packages/okam-core/src/swan/adapter/component.js b/packages/okam-core/src/swan/adapter/component.js new file mode 100644 index 00000000..a0ac9091 --- /dev/null +++ b/packages/okam-core/src/swan/adapter/component.js @@ -0,0 +1,35 @@ +/** + * @file Fix swan native component to adapt okam event handler. + * @author sparklewhy@gmail.com + */ + +'use strict'; + +import {normalizeEventArgs} from '../../helper/triggerEvent'; + +/** + * Emit custom component event + * + * @param {...any} args the event arguments + */ +function emit(...args) { + // fix custom component event args + normalizeEventArgs(this, args); + this.triggerEvent.apply(this, args); +} + +/** + * Make the native swan component to adapt to the okam framework + * + * @param {Object} component the component to adapt + * @return {Object} + */ +export default function adaptOKAM(component) { + let methods = component.methods || (component.methods = {}); + if (!methods.$emit) { + methods.$emit = emit; + } + return component; +} + +