diff --git a/CHANGELOG.md b/CHANGELOG.md index 0365bbf8c..f8381b162 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +### 2.4.0 + +> 2017-02-13 + +#### Features + +- feat(hook): add `doneEach` + + ### 2.3.0 > 2017-02-13 diff --git a/docs/plugins.md b/docs/plugins.md index 402588f12..2dd75e905 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -67,7 +67,7 @@ window.$docsify = { plugins: [ function (hook) { hook.init(function() { - // Called when the script starts running, only trigger once. + // Called when the script starts running, only trigger once, no arguments, }) hook.beforeEach(function(content) { @@ -84,8 +84,13 @@ window.$docsify = { next(html) }) + hook.doneEach(function() { + // Invoked each time after the data is fully loaded, no arguments, + // ... + }) + hook.ready(function() { - // Called after initialization is complete. Only trigger once. + // Called after initialization is complete. Only trigger once, no arguments. }) } ] diff --git a/docs/zh-cn/plugins.md b/docs/zh-cn/plugins.md index 30bcdd5d5..9fd249b79 100644 --- a/docs/zh-cn/plugins.md +++ b/docs/zh-cn/plugins.md @@ -63,7 +63,7 @@ window.$docsify = { plugins: [ function (hook) { hook.init(function() { - // 初始化时调用,只调用一次 + // 初始化时调用,只调用一次,没有参数。 }) hook.beforeEach(function(content) { @@ -79,8 +79,13 @@ window.$docsify = { next(html) }) + hook.doneEach(function() { + // 每次路由切换时数据全部加载完成后调用,没有参数。 + // ... + }) + hook.ready(function() { - // docsify 初始化完成后调用,只调用一次 + // 初始化完成后调用,只调用一次,没有参数。 }) } ] diff --git a/src/hook.js b/src/hook.js index 311103d9e..401765aed 100644 --- a/src/hook.js +++ b/src/hook.js @@ -4,6 +4,7 @@ export default class Hook { this.afterHooks = [] this.initHooks = [] this.readyHooks = [] + this.doneEachHooks = [] } beforeEach (fn) { @@ -14,6 +15,10 @@ export default class Hook { this.afterHooks.push(fn) } + doneEach (fn) { + this.doneEachHooks.push(fn) + } + init (fn) { this.initHooks.push(fn) } diff --git a/src/index.js b/src/index.js index 066d09490..75243a662 100644 --- a/src/index.js +++ b/src/index.js @@ -130,6 +130,7 @@ const Docsify = function () { mainRender(_ => { scrollIntoView() activeLink('nav') + window.Docsify.hook.emit('doneEach') }) } diff --git a/src/plugins/search.js b/src/plugins/search.js index b76e1d02b..0f0e762b1 100644 --- a/src/plugins/search.js +++ b/src/plugins/search.js @@ -342,7 +342,7 @@ const install = function () { new SearchComponent() !isAuto && searchPlugin() }) - isAuto && hook.beforeEach(searchPlugin) + isAuto && hook.doneEach(searchPlugin) }, window.$docsify.plugins) }