Skip to content

Commit

Permalink
feat: make vue and basic server renderer compatible in pure js runtimes
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Oct 3, 2017
1 parent 093673e commit c5d0fa0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/platforms/web/runtime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions src/platforms/web/runtime/transition-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
? window.requestAnimationFrame.bind(window)
: setTimeout
const raf = inBrowser
? window.requestAnimationFrame
? window.requestAnimationFrame.bind(window)
: setTimeout
: /* istanbul ignore next */ fn => fn()

export function nextFrame (fn: Function) {
raf(() => {
Expand Down
19 changes: 18 additions & 1 deletion src/server/write.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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)
}
Expand Down

0 comments on commit c5d0fa0

Please sign in to comment.