mirror of
https://gitee.com/vuejs/vue.git
synced 2024-12-02 12:07:39 +08:00
feat: make vue and basic server renderer compatible in pure js runtimes
This commit is contained in:
parent
093673e308
commit
c5d0fa0503
@ -44,7 +44,7 @@ Vue.prototype.$mount = function (
|
||||
|
||||
// devtools global hook
|
||||
/* istanbul ignore next */
|
||||
setTimeout(() => {
|
||||
Vue.nextTick(() => {
|
||||
if (config.devtools) {
|
||||
if (devtools) {
|
||||
devtools.emit('init', Vue)
|
||||
|
@ -58,9 +58,11 @@ if (hasTransition) {
|
||||
}
|
||||
|
||||
// binding to window is necessary to make hot reload work in IE in strict mode
|
||||
const raf = inBrowser && window.requestAnimationFrame
|
||||
const raf = inBrowser
|
||||
? window.requestAnimationFrame
|
||||
? window.requestAnimationFrame.bind(window)
|
||||
: setTimeout
|
||||
: /* istanbul ignore next */ fn => fn()
|
||||
|
||||
export function nextFrame (fn: Function) {
|
||||
raf(() => {
|
||||
|
@ -1,6 +1,23 @@
|
||||
/* @flow */
|
||||
|
||||
const MAX_STACK_DEPTH = 1000
|
||||
const noop = _ => _
|
||||
|
||||
const defer = typeof process !== 'undefined' && process.nextTick
|
||||
? process.nextTick
|
||||
: typeof Promise !== 'undefined'
|
||||
? fn => Promise.resolve().then(fn)
|
||||
: typeof setTimeout !== 'undefined'
|
||||
? setTimeout
|
||||
: noop
|
||||
|
||||
if (defer === noop) {
|
||||
throw new Error(
|
||||
'Your JavaScript runtime does not support any asynchronous primitives ' +
|
||||
'that are required by vue-server-renderer. Please use a polyfill for ' +
|
||||
'either Promise or setTimeout.'
|
||||
)
|
||||
}
|
||||
|
||||
export function createWriteFunction (
|
||||
write: (text: string, next: Function) => boolean,
|
||||
@ -14,7 +31,7 @@ export function createWriteFunction (
|
||||
const waitForNext = write(text, next)
|
||||
if (waitForNext !== true) {
|
||||
if (stackDepth >= MAX_STACK_DEPTH) {
|
||||
process.nextTick(() => {
|
||||
defer(() => {
|
||||
try { next() } catch (e) {
|
||||
onError(e)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user