Skip to content

Commit

Permalink
feat(hook): add doneEach
Browse files Browse the repository at this point in the history
  • Loading branch information
QingWei-Li committed Feb 13, 2017
1 parent 558d73c commit c6f7602
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 5 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
### 2.4.0

> 2017-02-13
#### Features

- feat(hook): add `doneEach`


### 2.3.0

> 2017-02-13
Expand Down
9 changes: 7 additions & 2 deletions docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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.
})
}
]
Expand Down
9 changes: 7 additions & 2 deletions docs/zh-cn/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ window.$docsify = {
plugins: [
function (hook) {
hook.init(function() {
// 初始化时调用,只调用一次
// 初始化时调用,只调用一次,没有参数。
})

hook.beforeEach(function(content) {
Expand All @@ -79,8 +79,13 @@ window.$docsify = {
next(html)
})

hook.doneEach(function() {
// 每次路由切换时数据全部加载完成后调用,没有参数。
// ...
})

hook.ready(function() {
// docsify 初始化完成后调用,只调用一次
// 初始化完成后调用,只调用一次,没有参数。
})
}
]
Expand Down
5 changes: 5 additions & 0 deletions src/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export default class Hook {
this.afterHooks = []
this.initHooks = []
this.readyHooks = []
this.doneEachHooks = []
}

beforeEach (fn) {
Expand All @@ -14,6 +15,10 @@ export default class Hook {
this.afterHooks.push(fn)
}

doneEach (fn) {
this.doneEachHooks.push(fn)
}

init (fn) {
this.initHooks.push(fn)
}
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ const Docsify = function () {
mainRender(_ => {
scrollIntoView()
activeLink('nav')
window.Docsify.hook.emit('doneEach')
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ const install = function () {
new SearchComponent()
!isAuto && searchPlugin()
})
isAuto && hook.beforeEach(searchPlugin)
isAuto && hook.doneEach(searchPlugin)
}, window.$docsify.plugins)
}

Expand Down

0 comments on commit c6f7602

Please sign in to comment.