diff --git a/src/core/config.js b/src/core/config.js index afa23272..ca3b7736 100644 --- a/src/core/config.js +++ b/src/core/config.js @@ -1,6 +1,10 @@ /* @flow */ -import { no, noop, identity } from 'shared/util' +import { + no, + noop, + identity +} from 'shared/util' export type Config = { // user @@ -18,13 +22,9 @@ export type Config = { isUnknownElement: (x?: string) => boolean; getTagNamespace: (x?: string) => string | void; mustUseProp: (tag: string, type: ?string, name: string) => boolean; - // internal - _assetTypes: Array; - _lifecycleHooks: Array; - _maxUpdateCount: number; }; -const config: Config = { +export default ({ /** * Option merge strategies (used in core/util/options) */ @@ -91,37 +91,5 @@ const config: Config = { * Check if an attribute must be bound using property, e.g. value * Platform-dependent. */ - mustUseProp: no, - - /** - * List of asset types that a component can own. - */ - _assetTypes: [ - 'component', - 'directive', - 'filter' - ], - - /** - * List of lifecycle hooks. - */ - _lifecycleHooks: [ - 'beforeCreate', - 'created', - 'beforeMount', - 'mounted', - 'beforeUpdate', - 'updated', - 'beforeDestroy', - 'destroyed', - 'activated', - 'deactivated' - ], - - /** - * Max circular updates allowed in a scheduler flush cycle. - */ - _maxUpdateCount: 100 -} - -export default config + mustUseProp: no +}: Config) diff --git a/src/core/global-api/assets.js b/src/core/global-api/assets.js index cbd0f884..2db49bfd 100644 --- a/src/core/global-api/assets.js +++ b/src/core/global-api/assets.js @@ -1,13 +1,14 @@ /* @flow */ import config from '../config' +import { ASSET_TYPES } from 'shared/constants' import { warn, isPlainObject } from '../util/index' export function initAssetRegisters (Vue: GlobalAPI) { /** * Create asset registration methods. */ - config._assetTypes.forEach(type => { + ASSET_TYPES.forEach(type => { Vue[type] = function ( id: string, definition: Function | Object diff --git a/src/core/global-api/extend.js b/src/core/global-api/extend.js index 8e5fc7cb..c8035a3d 100644 --- a/src/core/global-api/extend.js +++ b/src/core/global-api/extend.js @@ -1,6 +1,6 @@ /* @flow */ -import config from '../config' +import { ASSET_TYPES } from 'shared/constants' import { warn, extend, mergeOptions } from '../util/index' import { defineComputed, proxy } from '../instance/state' @@ -65,7 +65,7 @@ export function initExtend (Vue: GlobalAPI) { // create asset registers, so extended classes // can have their private assets too. - config._assetTypes.forEach(function (type) { + ASSET_TYPES.forEach(function (type) { Sub[type] = Super[type] }) // enable recursive self-lookup diff --git a/src/core/global-api/index.js b/src/core/global-api/index.js index fd53b1d7..03ffa0fb 100644 --- a/src/core/global-api/index.js +++ b/src/core/global-api/index.js @@ -6,6 +6,7 @@ import { initMixin } from './mixin' import { initExtend } from './extend' import { initAssetRegisters } from './assets' import { set, del } from '../observer/index' +import { ASSET_TYPES } from 'shared/constants' import builtInComponents from '../components/index' import { @@ -44,7 +45,7 @@ export function initGlobalAPI (Vue: GlobalAPI) { Vue.nextTick = nextTick Vue.options = Object.create(null) - config._assetTypes.forEach(type => { + ASSET_TYPES.forEach(type => { Vue.options[type + 's'] = Object.create(null) }) diff --git a/src/core/observer/scheduler.js b/src/core/observer/scheduler.js index 04d03488..8557758f 100644 --- a/src/core/observer/scheduler.js +++ b/src/core/observer/scheduler.js @@ -3,12 +3,15 @@ import type Watcher from './watcher' import config from '../config' import { callHook } from '../instance/lifecycle' + import { warn, nextTick, devtools } from '../util/index' +export const MAX_UPDATE_COUNT = 100 + const queue: Array = [] let has: { [key: number]: ?true } = {} let circular: { [key: number]: number } = {} @@ -55,7 +58,7 @@ function flushSchedulerQueue () { // in dev build, check and stop circular updates. if (process.env.NODE_ENV !== 'production' && has[id] != null) { circular[id] = (circular[id] || 0) + 1 - if (circular[id] > config._maxUpdateCount) { + if (circular[id] > MAX_UPDATE_COUNT) { warn( 'You may have an infinite update loop ' + ( watcher.user diff --git a/src/core/util/options.js b/src/core/util/options.js index 931dcb43..e3b1b718 100644 --- a/src/core/util/options.js +++ b/src/core/util/options.js @@ -4,13 +4,19 @@ import Vue from '../instance/index' import config from '../config' import { warn } from './debug' import { set } from '../observer/index' + +import { + ASSET_TYPES, + LIFECYCLE_HOOKS +} from 'shared/constants' + import { extend, - isPlainObject, hasOwn, camelize, capitalize, - isBuiltInTag + isBuiltInTag, + isPlainObject } from 'shared/util' /** @@ -125,7 +131,7 @@ function mergeHook ( : parentVal } -config._lifecycleHooks.forEach(hook => { +LIFECYCLE_HOOKS.forEach(hook => { strats[hook] = mergeHook }) @@ -143,7 +149,7 @@ function mergeAssets (parentVal: ?Object, childVal: ?Object): Object { : res } -config._assetTypes.forEach(function (type) { +ASSET_TYPES.forEach(function (type) { strats[type + 's'] = mergeAssets }) diff --git a/src/server/render.js b/src/server/render.js index 298bd3f8..4705e0ed 100644 --- a/src/server/render.js +++ b/src/server/render.js @@ -1,7 +1,7 @@ /* @flow */ import { escape } from 'he' -import { SSR_ATTR } from 'shared/util' +import { SSR_ATTR } from 'shared/constants' import { RenderContext } from './render-context' import { compileToFunctions } from 'web/compiler/index' import { createComponentInstanceForVnode } from 'core/vdom/create-component' diff --git a/src/shared/constants.js b/src/shared/constants.js new file mode 100644 index 00000000..2a4a7159 --- /dev/null +++ b/src/shared/constants.js @@ -0,0 +1,20 @@ +export const SSR_ATTR = 'data-server-rendered' + +export const ASSET_TYPES = [ + 'component', + 'directive', + 'filter' +] + +export const LIFECYCLE_HOOKS = [ + 'beforeCreate', + 'created', + 'beforeMount', + 'mounted', + 'beforeUpdate', + 'updated', + 'beforeDestroy', + 'destroyed', + 'activated', + 'deactivated' +] diff --git a/src/shared/util.js b/src/shared/util.js index 66134838..e88473e9 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -1,7 +1,5 @@ /* @flow */ -export const SSR_ATTR = 'data-server-rendered' - // these helpers produces better vm code in JS engines due to their // explicitness and function inlining export function isUndef (v: any): boolean { diff --git a/test/unit/modules/observer/scheduler.spec.js b/test/unit/modules/observer/scheduler.spec.js index 14219793..7daf31c8 100644 --- a/test/unit/modules/observer/scheduler.spec.js +++ b/test/unit/modules/observer/scheduler.spec.js @@ -1,6 +1,8 @@ import Vue from 'vue' -import config from 'core/config' -import { queueWatcher as _queueWatcher } from 'core/observer/scheduler' +import { + MAX_UPDATE_COUNT, + queueWatcher as _queueWatcher +} from 'core/observer/scheduler' function queueWatcher (watcher) { watcher.vm = {} // mock vm @@ -119,7 +121,7 @@ describe('Scheduler', () => { } queueWatcher(job) waitForUpdate(() => { - expect(count).toBe(config._maxUpdateCount + 1) + expect(count).toBe(MAX_UPDATE_COUNT + 1) expect('infinite update loop').toHaveBeenWarned() }).then(done) })