Skip to content

Commit 69e62f0

Browse files
committed
refactor: remove constants from config
1 parent d3aee4e commit 69e62f0

File tree

10 files changed

+54
-55
lines changed

10 files changed

+54
-55
lines changed

src/core/config.js

+8-40
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
/* @flow */
22

3-
import { no, noop, identity } from 'shared/util'
3+
import {
4+
no,
5+
noop,
6+
identity
7+
} from 'shared/util'
48

59
export type Config = {
610
// user
@@ -18,13 +22,9 @@ export type Config = {
1822
isUnknownElement: (x?: string) => boolean;
1923
getTagNamespace: (x?: string) => string | void;
2024
mustUseProp: (tag: string, type: ?string, name: string) => boolean;
21-
// internal
22-
_assetTypes: Array<string>;
23-
_lifecycleHooks: Array<string>;
24-
_maxUpdateCount: number;
2525
};
2626

27-
const config: Config = {
27+
export default ({
2828
/**
2929
* Option merge strategies (used in core/util/options)
3030
*/
@@ -91,37 +91,5 @@ const config: Config = {
9191
* Check if an attribute must be bound using property, e.g. value
9292
* Platform-dependent.
9393
*/
94-
mustUseProp: no,
95-
96-
/**
97-
* List of asset types that a component can own.
98-
*/
99-
_assetTypes: [
100-
'component',
101-
'directive',
102-
'filter'
103-
],
104-
105-
/**
106-
* List of lifecycle hooks.
107-
*/
108-
_lifecycleHooks: [
109-
'beforeCreate',
110-
'created',
111-
'beforeMount',
112-
'mounted',
113-
'beforeUpdate',
114-
'updated',
115-
'beforeDestroy',
116-
'destroyed',
117-
'activated',
118-
'deactivated'
119-
],
120-
121-
/**
122-
* Max circular updates allowed in a scheduler flush cycle.
123-
*/
124-
_maxUpdateCount: 100
125-
}
126-
127-
export default config
94+
mustUseProp: no
95+
}: Config)

src/core/global-api/assets.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
/* @flow */
22

33
import config from '../config'
4+
import { ASSET_TYPES } from 'shared/constants'
45
import { warn, isPlainObject } from '../util/index'
56

67
export function initAssetRegisters (Vue: GlobalAPI) {
78
/**
89
* Create asset registration methods.
910
*/
10-
config._assetTypes.forEach(type => {
11+
ASSET_TYPES.forEach(type => {
1112
Vue[type] = function (
1213
id: string,
1314
definition: Function | Object

src/core/global-api/extend.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* @flow */
22

3-
import config from '../config'
3+
import { ASSET_TYPES } from 'shared/constants'
44
import { warn, extend, mergeOptions } from '../util/index'
55
import { defineComputed, proxy } from '../instance/state'
66

@@ -65,7 +65,7 @@ export function initExtend (Vue: GlobalAPI) {
6565

6666
// create asset registers, so extended classes
6767
// can have their private assets too.
68-
config._assetTypes.forEach(function (type) {
68+
ASSET_TYPES.forEach(function (type) {
6969
Sub[type] = Super[type]
7070
})
7171
// enable recursive self-lookup

src/core/global-api/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { initMixin } from './mixin'
66
import { initExtend } from './extend'
77
import { initAssetRegisters } from './assets'
88
import { set, del } from '../observer/index'
9+
import { ASSET_TYPES } from 'shared/constants'
910
import builtInComponents from '../components/index'
1011

1112
import {
@@ -44,7 +45,7 @@ export function initGlobalAPI (Vue: GlobalAPI) {
4445
Vue.nextTick = nextTick
4546

4647
Vue.options = Object.create(null)
47-
config._assetTypes.forEach(type => {
48+
ASSET_TYPES.forEach(type => {
4849
Vue.options[type + 's'] = Object.create(null)
4950
})
5051

src/core/observer/scheduler.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
import type Watcher from './watcher'
44
import config from '../config'
55
import { callHook } from '../instance/lifecycle'
6+
67
import {
78
warn,
89
nextTick,
910
devtools
1011
} from '../util/index'
1112

13+
export const MAX_UPDATE_COUNT = 100
14+
1215
const queue: Array<Watcher> = []
1316
let has: { [key: number]: ?true } = {}
1417
let circular: { [key: number]: number } = {}
@@ -55,7 +58,7 @@ function flushSchedulerQueue () {
5558
// in dev build, check and stop circular updates.
5659
if (process.env.NODE_ENV !== 'production' && has[id] != null) {
5760
circular[id] = (circular[id] || 0) + 1
58-
if (circular[id] > config._maxUpdateCount) {
61+
if (circular[id] > MAX_UPDATE_COUNT) {
5962
warn(
6063
'You may have an infinite update loop ' + (
6164
watcher.user

src/core/util/options.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@ import Vue from '../instance/index'
44
import config from '../config'
55
import { warn } from './debug'
66
import { set } from '../observer/index'
7+
8+
import {
9+
ASSET_TYPES,
10+
LIFECYCLE_HOOKS
11+
} from 'shared/constants'
12+
713
import {
814
extend,
9-
isPlainObject,
1015
hasOwn,
1116
camelize,
1217
capitalize,
13-
isBuiltInTag
18+
isBuiltInTag,
19+
isPlainObject
1420
} from 'shared/util'
1521

1622
/**
@@ -125,7 +131,7 @@ function mergeHook (
125131
: parentVal
126132
}
127133

128-
config._lifecycleHooks.forEach(hook => {
134+
LIFECYCLE_HOOKS.forEach(hook => {
129135
strats[hook] = mergeHook
130136
})
131137

@@ -143,7 +149,7 @@ function mergeAssets (parentVal: ?Object, childVal: ?Object): Object {
143149
: res
144150
}
145151

146-
config._assetTypes.forEach(function (type) {
152+
ASSET_TYPES.forEach(function (type) {
147153
strats[type + 's'] = mergeAssets
148154
})
149155

src/server/render.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* @flow */
22

33
import { escape } from 'he'
4-
import { SSR_ATTR } from 'shared/util'
4+
import { SSR_ATTR } from 'shared/constants'
55
import { RenderContext } from './render-context'
66
import { compileToFunctions } from 'web/compiler/index'
77
import { createComponentInstanceForVnode } from 'core/vdom/create-component'

src/shared/constants.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export const SSR_ATTR = 'data-server-rendered'
2+
3+
export const ASSET_TYPES = [
4+
'component',
5+
'directive',
6+
'filter'
7+
]
8+
9+
export const LIFECYCLE_HOOKS = [
10+
'beforeCreate',
11+
'created',
12+
'beforeMount',
13+
'mounted',
14+
'beforeUpdate',
15+
'updated',
16+
'beforeDestroy',
17+
'destroyed',
18+
'activated',
19+
'deactivated'
20+
]

src/shared/util.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/* @flow */
22

3-
export const SSR_ATTR = 'data-server-rendered'
4-
53
// these helpers produces better vm code in JS engines due to their
64
// explicitness and function inlining
75
export function isUndef (v: any): boolean {

test/unit/modules/observer/scheduler.spec.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import Vue from 'vue'
2-
import config from 'core/config'
3-
import { queueWatcher as _queueWatcher } from 'core/observer/scheduler'
2+
import {
3+
MAX_UPDATE_COUNT,
4+
queueWatcher as _queueWatcher
5+
} from 'core/observer/scheduler'
46

57
function queueWatcher (watcher) {
68
watcher.vm = {} // mock vm
@@ -119,7 +121,7 @@ describe('Scheduler', () => {
119121
}
120122
queueWatcher(job)
121123
waitForUpdate(() => {
122-
expect(count).toBe(config._maxUpdateCount + 1)
124+
expect(count).toBe(MAX_UPDATE_COUNT + 1)
123125
expect('infinite update loop').toHaveBeenWarned()
124126
}).then(done)
125127
})

0 commit comments

Comments
 (0)