Skip to content
This repository has been archived by the owner on Jul 26, 2021. It is now read-only.

Commit

Permalink
feat: 修改registerHandler方法增加delay参数
Browse files Browse the repository at this point in the history
由于bridge初始化需要时间导致registerHandler方法失效
fixes #7
  • Loading branch information
Kntt committed Mar 12, 2019
1 parent ef93475 commit 3a41951
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/default.js
@@ -1,5 +1,7 @@
export default {
debug: true,
schemaName: 'yy',
delay: 200,
nativeHandlerName: 'nativeHandler',
mock: true,
mockHandler: null
Expand Down
10 changes: 7 additions & 3 deletions lib/plugin.js
Expand Up @@ -45,9 +45,13 @@ export default class VueJsBridgePlugin {
* 第二个参数是native提供的回调函数 callback,前端处理完成后可以通过 callback通知native
*/
registerHandler (name, fn) {
this.init(function (bridge) {
bridge.registerHandler(name, fn)
})
const { delay } = this.options
// birdge初始化需要时间,延迟处理注册方法
setTimeout(() => {
this.init(function (bridge) {
bridge.registerHandler(name, fn)
})
}, delay)
}
/**
* 前端调用native的方法
Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Expand Up @@ -20,6 +20,7 @@ interface Bridge<P = any, R = any, Q = any> {

export interface pluginOption<P = any, R = any> {
debug?: boolean
delay?: number
nativeHandlerName: string
mock?: boolean
mockHandler?: (payload: P, next:(response: R) => void) => void
Expand Down

0 comments on commit 3a41951

Please sign in to comment.