Skip to content

Commit 178203d

Browse files
committed
syntax update: v-ref, v-el; deprecate v-class & v-style
1 parent a9c354e commit 178203d

File tree

26 files changed

+125
-120
lines changed

26 files changed

+125
-120
lines changed

src/compiler/compile.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ var onRE = /^v-on:|^@/
1313
var literalRE = /#$/
1414
var argRE = /:(.*)$/
1515
var transitionRE = /^(v-bind:|:)?transition$/
16-
var nodeRefRE = /^\$\$\./
1716

1817
// terminal directives
1918
var terminalDirectives = [
@@ -560,14 +559,6 @@ function compileDirectives (attrs, options) {
560559
})
561560
} else
562561

563-
// node ref: $$.xxx
564-
if (nodeRefRE.test(name)) {
565-
value = _.camelize(name.replace(nodeRefRE, ''))
566-
pushDir('el', internalDirectives.el, {
567-
literal: true
568-
})
569-
} else
570-
571562
// event handlers
572563
if (onRE.test(name)) {
573564
pushDir('on', publicDirectives.on, {
@@ -579,7 +570,7 @@ function compileDirectives (attrs, options) {
579570
if (bindRE.test(name)) {
580571
dirName = name.replace(bindRE, '')
581572
if (dirName === 'style' || dirName === 'class') {
582-
pushDir(dirName, publicDirectives[dirName])
573+
pushDir(dirName, internalDirectives[dirName])
583574
} else {
584575
pushDir('bind', publicDirectives.bind, {
585576
arg: dirName

src/directive.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function Directive (descriptor, vm, el, host, scope, frag) {
3333
this.descriptor = descriptor
3434
this.name = descriptor.name
3535
this.expression = descriptor.expression
36+
this.arg = descriptor.arg
3637
this.filters = descriptor.filters
3738
this.literal = descriptor.literal
3839
// private
File renamed without changes.

src/directives/internal/component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports = {
2626

2727
// check ref
2828
this.ref = _.findRef(this.el)
29-
var refs = (this._scope || this.vm).$
29+
var refs = (this._scope || this.vm).$refs
3030
if (this.ref && !refs.hasOwnProperty(this.ref)) {
3131
_.defineReactive(refs, this.ref, null)
3232
}

src/directives/internal/el.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/directives/internal/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
exports.el = require('./el')
1+
exports.style = require('./style')
2+
exports['class'] = require('./class')
3+
exports.component = require('./component')
24
exports.prop = require('./prop')
35
exports.transition = require('./transition')
4-
exports.component = require('./component')
File renamed without changes.

src/directives/public/bind.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports = {
2323
priority: 850,
2424

2525
update: function (value) {
26-
var attr = this.descriptor.arg
26+
var attr = this.arg
2727
if (inputProps[attr] && attr in this.el) {
2828
if (!this.valueRemoved) {
2929
this.el.removeAttribute(attr)

src/directives/public/el.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
var _ = require('../../util')
2+
3+
module.exports = {
4+
5+
priority: 1500,
6+
7+
bind: function () {
8+
if (!this.arg) {
9+
process.env.NODE_ENV !== 'production' && _.warn(
10+
'v-el requires an argument.'
11+
)
12+
return
13+
}
14+
var id = this.id = _.camelize(this.arg)
15+
var refs = (this._scope || this.vm).$els
16+
if (refs.hasOwnProperty(id)) {
17+
refs[id] = this.el
18+
} else {
19+
_.defineReactive(refs, id, this.el)
20+
}
21+
},
22+
23+
unbind: function () {
24+
if (!this.id) return
25+
var refs = (this._scope || this.vm).$els
26+
if (refs[this.id] === this.el) {
27+
refs[this.id] = null
28+
}
29+
}
30+
}

src/directives/public/for.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ module.exports = {
200200
var parentScope = this._scope || this.vm
201201
var scope = Object.create(parentScope)
202202
// ref holder for the scope
203-
scope.$ = {}
203+
scope.$refs = {}
204+
scope.$els = {}
204205
// make sure point $parent to parent scope
205206
scope.$parent = parentScope
206207
// for two-way binding on alias
@@ -227,7 +228,7 @@ module.exports = {
227228
updateRef: function () {
228229
var ref = this.ref
229230
if (!ref) return
230-
var hash = (this._scope || this.vm).$
231+
var hash = (this._scope || this.vm).$refs
231232
var refs
232233
if (!this.converted) {
233234
refs = this.frags.map(findVmFromFrag)
@@ -499,7 +500,7 @@ module.exports = {
499500

500501
unbind: function () {
501502
if (this.ref) {
502-
(this._scope || this.vm).$[this.ref] = null
503+
(this._scope || this.vm).$refs[this.ref] = null
503504
}
504505
if (this.frags) {
505506
var i = this.frags.length

0 commit comments

Comments
 (0)