regularjs / regular

regularjs: a living template engine that helps us to create data-driven component.
http://regularjs.github.io/
MIT License
1.06k stars 149 forks source link

enter 和 init #192

Closed leileiqiu closed 7 years ago

leileiqiu commented 7 years ago

enter 和 init 有什么区别?

fengzilong commented 7 years ago

enter是regular-state中引入的钩子,对应stateman中的enter生命周期钩子,init是regular自身提供的钩子,在组件实例化时触发

以下描述都是假设你使用了regular-state

无论如何,每次路由进入都会触发enter 如果rebuild配置为false,那么init只会在第一次实例化组件时触发(发生在enter前) 如果rebuild配置为true,那么每次enter前都会重新实例化,触发init(发生在enter前)

可以直接看下代码 https://github.com/regularjs/regular-state/blob/master/restate-full.js#L161-L255