1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| const _Page = Page Page = (options = {}) => { const mixins = options.mixins if (Array.isArray(mixins)) { Reflect.deleteProperty(options, 'mixins') options = merge(mixins, options) } console.log(options); _Page(options) }
const properties = ['data', 'properties', 'options'] const methods = ['onLoad', 'onShow', 'onReady', 'onHide', 'onUnload', 'onPullDownRefresh', 'onReachBottom', 'onShareAppMessage', 'onPageScroll', 'onResize', 'onTabItemTap']
const merge = (mixins, options) => { mixins.forEach(mixin => { if (Object.prototype.toString.call(mixin).slice(8, -1) !== 'Object') { throw new Error('mixin is not an object') } for (const [k, v] of Object.entries(mixin)) { if (properties.includes(k)) { options[k] = { ...v, ...options[k]} } else if (methods.includes(k)) { const func = options[k] options[k] = function(...arg) { v.call(this, ...arg) func && func.call(this, ...arg) } } else { console.log(mixin[k]) options = { ...mixin, ...options} console.log(options); } } }) return options }
|