Skip to content

Commit 91e4d47

Browse files
committed
support colon prefix shorthand for bind-
1 parent b5a2520 commit 91e4d47

File tree

12 files changed

+60
-35
lines changed

12 files changed

+60
-35
lines changed

examples/commits/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ <h1>Latest Vue.js Commits</h1>
2626
<template v-for="branch in branches">
2727
<input type="radio"
2828
name="branch"
29-
bind-id="branch"
30-
bind-value="branch"
29+
:id="branch"
30+
:value="branch"
3131
v-model="currentBranch">
32-
<label bind-for="branch">{{branch}}</label>
32+
<label :for="branch">{{branch}}</label>
3333
</template>
3434
<p>yyx990803/vue@{{currentBranch}}</p>
3535
<ul>
3636
<li v-for="record in commits">
37-
<a bind-href="record.html_url" target="_blank" class="commit">{{record.sha.slice(0, 7)}}</a>
37+
<a :href="record.html_url" target="_blank" class="commit">{{record.sha.slice(0, 7)}}</a>
3838
- <span class="message">{{record.commit.message | truncate}}</span><br>
3939
by <span class="author">{{record.commit.author.name}}</span>
4040
at <span class="date">{{record.commit.author.date | formatDate}}</span>

examples/grid/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
<tr>
1616
<th v-for="key in columns"
1717
on-click="sortBy(key)"
18-
bind-class="{active: sortKey == key}">
18+
:class="{active: sortKey == key}">
1919
{{key | capitalize}}
2020
<span class="arrow"
21-
bind-class="reversed[key] ? 'dsc' : 'asc'">
21+
:class="reversed[key] ? 'dsc' : 'asc'">
2222
</span>
2323
</th>
2424
</tr>
@@ -42,9 +42,9 @@
4242
Search <input name="query" v-model="searchQuery">
4343
</form>
4444
<demo-grid
45-
bind-data="gridData"
46-
bind-columns="gridColumns"
47-
bind-filter-key="searchQuery">
45+
:data="gridData"
46+
:columns="gridColumns"
47+
:filter-key="searchQuery">
4848
</demo-grid>
4949
</div>
5050

examples/modal/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
<div id="app">
5858
<button id="show-modal" on-click="showModal = true">Show Modal</button>
5959
<!-- use the modal component, pass in the prop -->
60-
<modal bind-show="@showModal">
60+
<modal :show="@showModal">
6161
<!--
6262
you can use custom content here to overwrite
6363
default content

examples/svg/index.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,27 @@
1111
<!-- template for the polygraph component. -->
1212
<script type="text/x-template" id="polygraph-template">
1313
<g>
14-
<polygon bind-points="points"></polygon>
14+
<polygon :points="points"></polygon>
1515
<circle cx="100" cy="100" r="80"></circle>
1616
<axis-label
1717
v-for="stat in stats"
18-
bind-stat="stat"
19-
bind-index="$index"
20-
bind-total="stats.length">
18+
:stat="stat"
19+
:index="$index"
20+
:total="stats.length">
2121
</axis-label>
2222
</g>
2323
</script>
2424

2525
<!-- template for the axis label component. -->
2626
<script type="text/x-template" id="axis-label-template">
27-
<text bind-x="point.x" bind-y="point.y">{{stat.label}}</text>
27+
<text :x="point.x" :y="point.y">{{stat.label}}</text>
2828
</script>
2929

3030
<!-- demo root element -->
3131
<div id="demo">
3232
<!-- Use the component -->
3333
<svg width="200" height="200">
34-
<polygraph bind-stats="stats"></polygraph>
34+
<polygraph :stats="stats"></polygraph>
3535
</svg>
3636
<!-- controls -->
3737
<div v-for="stat in stats">

examples/todomvc/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ <h1>todos</h1>
2121
<ul class="todo-list">
2222
<li class="todo"
2323
v-for="todo in filteredTodos"
24-
bind-class="{completed: todo.completed, editing: todo == editedTodo}">
24+
:class="{completed: todo.completed, editing: todo == editedTodo}">
2525
<div class="view">
2626
<input class="toggle" type="checkbox" v-model="todo.completed">
2727
<label on-dblclick="editTodo(todo)">{{todo.title}}</label>
@@ -41,9 +41,9 @@ <h1>todos</h1>
4141
<strong v-text="remaining"></strong> {{remaining | pluralize 'item'}} left
4242
</span>
4343
<ul class="filters">
44-
<li><a href="#/all" bind-class="{selected: visibility == 'all'}">All</a></li>
45-
<li><a href="#/active" bind-class="{selected: visibility == 'active'}">Active</a></li>
46-
<li><a href="#/completed" bind-class="{selected: visibility == 'completed'}">Completed</a></li>
44+
<li><a href="#/all" :class="{selected: visibility == 'all'}">All</a></li>
45+
<li><a href="#/active" :class="{selected: visibility == 'active'}">Active</a></li>
46+
<li><a href="#/completed" :class="{selected: visibility == 'completed'}">Completed</a></li>
4747
</ul>
4848
<button class="clear-completed" on-click="removeCompleted" v-show="todos.length > remaining">
4949
Clear completed

examples/tree/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<script type="text/x-template" id="item-template">
2929
<li>
3030
<div
31-
bind-class="{bold: isFolder}"
31+
:class="{bold: isFolder}"
3232
on-click="toggle"
3333
on-dblclick="changeType">
3434
{{model.name}}
@@ -38,7 +38,7 @@
3838
<item
3939
class="item"
4040
v-for="model in model.children"
41-
bind-model="model">
41+
:model="model">
4242
</item>
4343
<li on-click="addChild">+</li>
4444
</ul>
@@ -51,7 +51,7 @@
5151
<ul id="demo">
5252
<item
5353
class="item"
54-
bind-model="treeData">
54+
:model="treeData">
5555
</item>
5656
</ul>
5757

src/compiler/compile-props.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,10 @@ module.exports = function compileProps (el, propOptions) {
103103
}
104104
} else {
105105
// new syntax
106-
attr = 'bind-' + attr
107-
value = prop.raw = el.getAttribute(attr)
106+
value = prop.raw = _.getBindAttr(el, attr)
108107
if (value !== null) {
109108
// mark it so we know this is a bind
110109
prop.bindSyntax = true
111-
el.removeAttribute(attr)
112110
parsed = dirParser.parse(value)
113111
value = parsed.expression
114112
prop.filters = parsed.filters

src/compiler/compile.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var resolveAsset = _.resolveAsset
99
var componentDef = require('../directives/component')
1010

1111
// special binding prefixes
12-
var bindRE = /^bind-/
12+
var bindRE = /^bind-|^:/
1313
var onRE = /^on-/
1414

1515
// terminal directives
@@ -586,7 +586,7 @@ function compileDirectives (attrs, options) {
586586
} else
587587

588588
// special case for el
589-
if (name === 'el' || name === 'bind-el') {
589+
if (name === 'el' || name === 'bind-el' || name === ':el') {
590590
dirs.push({
591591
name: 'el',
592592
arg: bindRE.test(name),
@@ -596,7 +596,7 @@ function compileDirectives (attrs, options) {
596596
} else
597597

598598
// special case for transition
599-
if (name === 'transition' || name === 'bind-transition') {
599+
if (name === 'transition' || name === 'bind-transition' || name === ':transition') {
600600
dirs.push({
601601
name: 'transition',
602602
arg: bindRE.test(name),

src/directive.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,19 @@ Directive.prototype._bind = function () {
6767
// TODO simplify this
6868
if (name === 'attr') {
6969
this.el.removeAttribute('bind-' + this.arg)
70+
this.el.removeAttribute(':' + this.arg)
7071
} else if (name === 'class' || name === 'style') {
7172
this.el.removeAttribute('bind-' + name)
73+
this.el.removeAttribute(':' + name)
7274
} else if (name === 'on') {
7375
this.el.removeAttribute('on-' + this.arg)
7476
} else if (name === 'transition' || name === 'el') {
75-
this.el.removeAttribute(this.arg ? 'bind-' + name : name)
77+
if (this.arg) {
78+
this.el.removeAttribute('bind-' + name)
79+
this.el.removeAttribute(':' + name)
80+
} else {
81+
this.el.removeAttribute(name)
82+
}
7683
}
7784
}
7885
if (typeof def === 'function') {
@@ -197,9 +204,8 @@ Directive.prototype.param = function (name) {
197204
this.el.removeAttribute(name)
198205
param = (this._scope || this.vm).$interpolate(param)
199206
} else {
200-
param = this.el.getAttribute('bind-' + name)
207+
param = _.getBindAttr(this.el, name)
201208
if (param != null) {
202-
this.el.removeAttribute('bind-' + name)
203209
param = (this._scope || this.vm).$eval(param)
204210
process.env.NODE_ENV !== 'production' && _.log(
205211
'You are using bind- syntax on "' + name + '", which ' +

src/element-directives/partial.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = {
2525
this.insert(id)
2626
}
2727
} else {
28-
id = el.getAttribute('bind-name')
28+
id = el.getAttribute('bind-name') || el.getAttribute(':name')
2929
if (id) {
3030
this.setupDynamic(id)
3131
}

0 commit comments

Comments
 (0)