Skip to content

Commit

Permalink
feat(wx-mini): 添加component中手势行为收集
Browse files Browse the repository at this point in the history
  • Loading branch information
umbrellaZwl committed Feb 4, 2021
1 parent 14ad198 commit 48cb940
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 36 deletions.
3 changes: 2 additions & 1 deletion src/wx-mini/load.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { EVENTTYPES } from '@/common/constant'
import { HandleWxConsoleEvents, HandleNetworkEvents, HandleWxEvents } from './handleWxEvents'
import { addReplaceHandler, replaceApp, replacePage } from './replace'
import { addReplaceHandler, replaceApp, replacePage, replaceComponent } from './replace'

export function setupReplace() {
replaceApp()
replacePage()
replaceComponent()
addReplaceHandler({
callback: (data) => HandleWxEvents.handleRoute(data),
type: EVENTTYPES.MINI_ROUTE
Expand Down
50 changes: 15 additions & 35 deletions src/wx-mini/replace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,45 +108,25 @@ export function replacePage() {
)
})
replaceAction(pageOptions)
// function isNotAction(method) {
// // 如果是method中处理过的方法,则不是处理用户手势行为的方法
// return methods.find((m) => m.replace('PageOn', 'on') === method)
// }
// addReplaceHandler({
// callback: (data) => HandleWxPageEvents.onAction(data),
// type: EVENTTYPES.DOM
// })
// function gestureTrigger(e) {
// e.mitoProcessed = true // 给事件对象增加特殊的标记,避免被无限透传
// triggerHandlers(EVENTTYPES.DOM, e)
// }
// const throttleGesturetrigger = throttle(gestureTrigger, 500)
// const linstenerTypes = [ELinstenerTypes.Touchmove, ELinstenerTypes.Tap]
// Object.keys(pageOptions).forEach((m) => {
// if ('function' !== typeof pageOptions[m] || isNotAction(m)) {
// return
// }
// replaceOld(
// pageOptions,
// m,
// function (originMethod: (args: any) => void) {
// return function (...args: any): void {
// const e = args[0]
// if (e && e.type && e.currentTarget && !e.mitoProcessed) {
// if (linstenerTypes.indexOf(e.type)) {
// throttleGesturetrigger(e)
// }
// }
// originMethod.apply(this, args)
// }
// },
// true
// )
// })
return originPage.call(this, pageOptions)
}
}

export function replaceComponent() {
if (!Component) {
return
}
const originComponent = Component
//TODO: components全局类型定义没有识别出来
// @ts-ignore
Component = function (componentOptions): WechatMiniprogram.Component.Constructor {
if (typeof componentOptions.methods === 'object') {
replaceAction(componentOptions.methods)
}
return originComponent.call(this, componentOptions)
}
}

function replaceAction(options: WechatMiniprogram.Page.Options<any, any>) {
addReplaceHandler({
callback: (data) => HandleWxPageEvents.onAction(data),
Expand Down

0 comments on commit 48cb940

Please sign in to comment.