refactor(core): adjust directory structure:

This commit is contained in:
qingwei.li 2017-02-16 23:37:39 +08:00 • committed by cinwell.li
commit aad62b65f5
20 changed files with 381 additions and 93 deletions

27
src/core/init/index.js Normal file
View file

@ -0,0 +1,27 @@
import config from '../config'
import { initLifecycle, callHook } from './lifecycle'
import { initRender } from '../render'
import { initRoute } from '../route'
import { initEvent } from '../event'
import { initFetch } from '../fetch'
import { isFn } from '../util/core'
export function initMixin (Docsify) {
Docsify.prototype._init = function () {
const vm = this
vm._config = config || {}
initLifecycle(vm) // Init hooks
initPlugin(vm) // Install plugins
callHook(vm, 'init')
initRender(vm) // Render base DOM
initEvent(vm) // Bind events
initRoute(vm) // Add hashchange eventListener
initFetch(vm) // Fetch data
callHook(vm, 'ready')
}
}
function initPlugin (vm) {
[].concat(vm.config.plugins).forEach(fn => isFn(fn) && fn(vm.bindHook))
}