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

37
src/core/fetch/ajax.js Normal file
View file

@ -0,0 +1,37 @@
import progressbar from '../render/progressbar'
import { noop } from '../util/core'
/**
* Simple ajax get
* @param {String} url
* @param {Boolean} [loading=false] has loading bar
* @return { then(resolve, reject), abort }
*/
export function get (url, hasLoading = false) {
const xhr = new XMLHttpRequest()
xhr.open('GET', url)
xhr.send()
return {
then: function (success, error = noop) {
const on = xhr.addEventListener
if (hasLoading) {
const id = setInterval(_ => progressbar({}), 500)
on('progress', progressbar)
on('loadend', evt => {
progressbar(evt)
clearInterval(id)
})
}
on('error', error)
on('load', ({ target }) => {
target.status >= 400 ? error(target) : success(target.response)
})
},
abort: () => xhr.readyState !== 4 && xhr.abort()
}
}

13
src/core/fetch/index.js Normal file
View file

@ -0,0 +1,13 @@
import { callHook } from '../init/lifecycle'
export function fetchMixin (Docsify) {
Docsify.prototype.$fetch = function () {
}
}
export function initFetch (vm) {
vm.$fetch(result => {
vm.$resetEvents()
callHook(vm, 'doneEach')
})
}