-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli h5 redux-h5 router): h5路由的一些改动
- 增加了Taro.getApp - 调整了内部路由参数的传递方式 - 调整了componentDidShow、componentDidHide的实现 - 修复后退两次报错的问题 - 更新router包的依赖 - taro-h5类型文件更新
- Loading branch information
Showing
12 changed files
with
176 additions
and
235 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
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,38 +1,21 @@ | ||
import Nerv from 'nervjs' | ||
import Taro from './index' | ||
|
||
class Component extends Nerv.Component { | ||
get $router () { | ||
if (this.context && this.context.router) { | ||
return this.context.router.location | ||
} | ||
return Taro.getRouter() | ||
} | ||
set $router (args) { | ||
console.warn('Property "$router" is read-only.') | ||
} | ||
|
||
get $app () { | ||
if (!this.vnode) return {} | ||
if (!this._$app) this._$app = getApp(this) | ||
return this._$app | ||
return Taro.getApp() | ||
} | ||
|
||
set $app (app) { | ||
console.warn('Property "$app" is read-only.') | ||
} | ||
} | ||
|
||
/** | ||
* 往上遍历直到找到根节点 | ||
* @param {Nerv Component} component 当前的组件实例 | ||
* @return {Nerv Component} 根节点实例 | ||
*/ | ||
function getApp (component) { | ||
const vnode = component.vnode | ||
|
||
if (!vnode) return {} | ||
if (vnode._owner) return getApp(vnode._owner) | ||
|
||
return component | ||
} | ||
|
||
export default 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,16 @@ | ||
/** | ||
* 尝试调用函数 | ||
* | ||
* @param {function} func 调用的函数 | ||
* @param {any} ctx 调用上下文 | ||
* @param {...any} args 函数调用参数 | ||
* @returns {any} returnValue | ||
*/ | ||
export const tryToCall = (func, ctx = null, ...args) => { | ||
if (!func) return | ||
if (ctx) { | ||
return func.apply(ctx, args) | ||
} else { | ||
return func(...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
Oops, something went wrong.