8000 component · bencode/vue@f562052 · GitHub
[go: up one dir, main page]

Skip to content

Commit f562052

Browse files
committed
component
1 parent 801039f commit f562052

File tree

2 files changed

+43
-27
lines changed

2 files changed

+43
-27
lines changed

src/directives/internal/component.js

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
var _ = require('../../util')
21
import { cloneNode } from '../../parsers/template'
2+
import {
3+
extractContent,
4+
createAnchor,
5+
replace,
6+
hyphenate,
7+
warn,
8+
cancellable,
9+
extend
10+
} from '../../util'
311

4-
module.exports = {
12+
export default {
513

614
priority: 1500,
715

@@ -21,7 +29,7 @@ module.exports = {
2129
* <component :is="view">
2230
*/
2331

24-
bind: function () {
32+
bind () {
2533
if (!this.el.__vue__) {
2634
// keep-alive cache
2735
this.keepAlive = this.params.keepAlive
@@ -31,7 +39,7 @@ module.exports = {
3139
// check inline-template
3240
if (this.params.inlineTemplate) {
3341
// extract inline template as a DocumentFragment
34-
this.inlineTemplate = _.extractContent(this.el, true)
42+
this.inlineTemplate = extractContent(this.el, true)
3543
}
3644
// component resolution related state
3745
this.pendingComponentCb =
@@ -40,23 +48,23 @@ module.exports = {
4048
this.pendingRemovals = 0
4149
this.pendingRemovalCb = null
4250
// create a ref anchor
43-
this.anchor = _.createAnchor('v-component')
44-
_.replace(this.el, this.anchor)
51+
this.anchor = createAnchor('v-component')
52+
replace(this.el, this.anchor)
4553
// remove is attribute.
4654
// this is removed during compilation, but because compilation is
4755
// cached, when the component is used elsewhere this attribute
4856
// will remain at link time.
4957
this.el.removeAttribute('is')
5058
// remove ref, same as above
5159
if (this.descriptor.ref) {
52-
this.el.removeAttribute('v-ref:' + _.hyphenate(this.descriptor.ref))
60+
this.el.removeAttribute('v-ref:' + hyphenate(this.descriptor.ref))
5361
}
5462
// if static, build right now.
5563
if (this.literal) {
5664
this.setComponent(this.expression)
5765
}
5866
} else {
59-
process.env.NODE_ENV !== 'production' && _.warn(
67+
process.env.NODE_ENV !== 'production' && warn(
6068
'cannot mount component "' + this.expression + '" ' +
6169
'on already mounted element: ' + this.el
6270
)
@@ -68,7 +76,7 @@ module.exports = {
6876
* literal scenario, e.g. <component :is="view">
6977
*/
7078

71-
update: function (value) {
79+
update (value) {
7280
if (!this.literal) {
7381
this.setComponent(value)
7482
}
@@ -87,7 +95,7 @@ module.exports = {
8795
* @param {Function} [cb]
8896
*/
8997

90-
setComponent: function (value, cb) {
98+
setComponent (value, cb) {
9199
this.invalidatePending()
92100
if (!value) {
93101
// just remove current
@@ -107,9 +115,9 @@ module.exports = {
107115
* the child vm.
108116
*/
109117

110-
resolveComponent: function (id, cb) {
118+
resolveComponent (id, cb) {
111119
var self = this
112-
this.pendingComponentCb = _.cancellable(function (Component) {
120+
this.pendingComponentCb = cancellable(function (Component) {
113121
self.ComponentName = Component.options.name || id
114122
self.Component = Component
115123
cb()
@@ -126,7 +134,7 @@ module.exports = {
126134
* @param {Function} [cb]
127135
*/
128136

129-
mountComponent: function (cb) {
137+
mountComponent (cb) {
130138
// actual mount
131139
this.unbuild(true)
132140
var self = this
@@ -154,7 +162,7 @@ module.exports = {
154162
* pending callback.
155163
*/
156164

157-
invalidatePending: function () {
165+
invalidatePending () {
158166
if (this.pendingComponentCb) {
159167
this.pendingComponentCb.cancel()
160168
this.pendingComponentCb = null
@@ -170,7 +178,7 @@ module.exports = {
170178
* @return {Vue} - the created instance
171179
*/
172180

173-
build: function (extraOptions) {
181+
build (extraOptions) {
174182
var cached = this.getCached()
175183
if (cached) {
176184
return cached
@@ -210,7 +218,7 @@ module.exports = {
210218
// in 1.0.0 this is used by vue-router only
211219
/* istanbul ignore if */
212220
if (extraOptions) {
213-
_.extend(options, extraOptions)
221+
extend(options, extraOptions)
214222
}
215223
var child = new this.Component(options)
216224
if (this.keepAlive) {
@@ -220,7 +228,7 @@ module.exports = {
220228
if (process.env.NODE_ENV !== 'production' &&
221229
this.el.hasAttribute('transition') &&
222230
child._isFragment) {
223-
_.warn(
231+
warn(
224232
'Transitions will not work on a fragment instance. ' +
225233
'Template: ' + child.$options.template
226234
)
@@ -235,7 +243,7 @@ module.exports = {
235243
* @return {Vue|undefined}
236244
*/
237245

238-
getCached: function () {
246+
getCached () {
239247
return this.keepAlive && this.cache[this.Component.cid]
240248
},
241249

@@ -246,7 +254,7 @@ module.exports = {
246254
* @param {Boolean} defer
247255
*/
248256

249-
unbuild: function (defer) {
257+
unbuild (defer) {
250258
if (this.waitingFor) {
251259
this.waitingFor.$destroy()
252260
this.waitingFor = null
@@ -272,7 +280,7 @@ module.exports = {
272280
* @param {Function} cb
273281
*/
274282

275-
remove: function (child, cb) {
283+
remove (child, cb) {
276284
var keepAlive = this.keepAlive
277285
if (child) {
278286
// we may have a component switch when a previous
@@ -303,7 +311,7 @@ module.exports = {
303311
* @param {Function} [cb]
304312
*/
305313

306-
transition: function (target, cb) {
314+
transition (target, cb) {
307315
var self = this
308316
var current = this.childVM
309317
// for devtool inspection
@@ -333,7 +341,7 @@ module.exports = {
333341
* Unbind.
334342
*/
335343

336-
unbind: function () {
344+
unbind () {
337345
this.invalidatePending()
338346
// Do not defer cleanup when unbinding
339347
this.unbuild()

src/directives/internal/index.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
exports.style = require('./style')
2-
exports['class'] = require('./class')
3-
exports.component = require('./component')
4-
exports.prop = require('./prop')
5-
exports.transition = require('./transition')
1+
import style from './style'
2+
import vClass from './class'
3+
import component from './component'
4+
import prop from './prop'
5+
import transition from './transition'
6+
7+
export default {
8+
style,
9+
'class': vClass,
10+
component,
11+
prop,
12+
transition
13+
}

0 commit comments

Comments
 (0)
0