Skip to content

Commit 6be817e

Browse files
committed
prefix internal directive methods with $ so its less confusing
1 parent 1eea0df commit 6be817e

File tree

9 files changed

+43
-46
lines changed

9 files changed

+43
-46
lines changed

src/binding.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ BindingProto._update = function () {
5252
var i = this.dirs.length,
5353
value = this.val()
5454
while (i--) {
55-
this.dirs[i].update(value)
55+
this.dirs[i].$update(value)
5656
}
5757
this.pub()
5858
}
@@ -89,7 +89,7 @@ BindingProto.unbind = function () {
8989
this.unbound = true
9090
var i = this.dirs.length
9191
while (i--) {
92-
this.dirs[i].unbind()
92+
this.dirs[i].$unbind()
9393
}
9494
i = this.deps.length
9595
var subs

src/compiler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ CompilerProto.bindDirective = function (directive, bindingOwner) {
681681
directive.bind(value)
682682
}
683683
// set initial value
684-
directive.update(value, true)
684+
directive.$update(value, true)
685685
}
686686

687687
/**
@@ -955,7 +955,7 @@ CompilerProto.destroy = function () {
955955
if (j > -1) dirs.splice(j, 1)
956956
}
957957
}
958-
dir.unbind()
958+
dir.$unbind()
959959
}
960960

961961
// unbind all computed, anonymous bindings

src/directive.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,10 @@ function Directive (name, ast, definition, compiler, el) {
2525

2626
// mix in properties from the directive definition
2727
if (typeof definition === 'function') {
28-
this[isEmpty ? 'bind' : '_update'] = definition
28+
this[isEmpty ? 'bind' : 'update'] = definition
2929
} else {
3030
for (var prop in definition) {
31-
if (prop === 'unbind' || prop === 'update') {
32-
this['_' + prop] = definition[prop]
33-
} else {
34-
this[prop] = definition[prop]
35-
}
31+
this[prop] = definition[prop]
3632
}
3733
}
3834

@@ -88,13 +84,14 @@ var DirProto = Directive.prototype
8884
* for computed properties, this will only be called once
8985
* during initialization.
9086
*/
91-
DirProto.update = function (value, init) {
87+
DirProto.$update = function (value, init) {
88+
if (this.$lock) return
9289
if (init || value !== this.value || (value && typeof value === 'object')) {
9390
this.value = value
94-
if (this._update) {
95-
this._update(
91+
if (this.update) {
92+
this.update(
9693
this.filters && !this.computeFilters
97-
? this.applyFilters(value)
94+
? this.$applyFilters(value)
9895
: value,
9996
init
10097
)
@@ -105,7 +102,7 @@ DirProto.update = function (value, init) {
105102
/**
106103
* pipe the value through filters
107104
*/
108-
DirProto.applyFilters = function (value) {
105+
DirProto.$applyFilters = function (value) {
109106
var filtered = value, filter
110107
for (var i = 0, l = this.filters.length; i < l; i++) {
111108
filter = this.filters[i]
@@ -117,10 +114,10 @@ DirProto.applyFilters = function (value) {
117114
/**
118115
* Unbind diretive
119116
*/
120-
DirProto.unbind = function () {
117+
DirProto.$unbind = function () {
121118
// this can be called before the el is even assigned...
122119
if (!this.el || !this.vm) return
123-
if (this._unbind) this._unbind()
120+
if (this.unbind) this.unbind()
124121
this.vm = this.el = this.binding = this.compiler = null
125122
}
126123

src/directives/if.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module.exports = {
3232
update: function (value) {
3333

3434
if (!value) {
35-
this._unbind()
35+
this.unbind()
3636
} else if (!this.childVM) {
3737
this.childVM = new this.Ctor({
3838
el: this.el.cloneNode(true),

src/directives/on.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = {
1818
utils.warn('Directive "v-on:' + this.expression + '" expects a method.')
1919
return
2020
}
21-
this._unbind()
21+
this.unbind()
2222
var vm = this.vm,
2323
context = this.context
2424
this.handler = function (e) {

src/directives/view.js

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

2626
update: function(value) {
2727

28-
this._unbind()
28+
this.unbind()
2929

3030
var Ctor = this.compiler.getOption('components', value)
3131
if (!Ctor) return

test/unit/specs/binding.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('Binding', function () {
3737
pubbed = false,
3838
numInstances = 3,
3939
instance = {
40-
update: function (value) {
40+
$update: function (value) {
4141
updated += value
4242
}
4343
}
@@ -135,7 +135,7 @@ describe('Binding', function () {
135135
unbound = 0,
136136
numInstances = 3,
137137
instance = {
138-
unbind: function () {
138+
$unbind: function () {
139139
unbound++
140140
}
141141
}

test/unit/specs/directive.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ describe('Directive', function () {
148148

149149
describe('instantiation', function () {
150150

151-
it('should copy the definition as _update if the def is a function', function () {
151+
it('should copy the definition as update if the def is a function', function () {
152152

153153
var testDir = function () {}
154154
directives.test = testDir
155155

156156
var d = build('test', 'abc', compiler)
157-
assert.strictEqual(d._update, testDir)
157+
assert.strictEqual(d.update, testDir)
158158
})
159159

160160
it('should copy methods if the def is an object', function () {
@@ -168,8 +168,8 @@ describe('Directive', function () {
168168
directives.obj = obj
169169

170170
var d = build('obj', 'abc', compiler)
171-
assert.strictEqual(d._update, obj.update, 'update should be copied as _update')
172-
assert.strictEqual(d._unbind, obj.unbind, 'unbind should be copied as _unbind')
171+
assert.strictEqual(d.update, obj.update)
172+
assert.strictEqual(d.unbind, obj.unbind)
173173
assert.strictEqual(d.bind, obj.bind)
174174
assert.strictEqual(d.custom, obj.custom, 'should copy any custom methods')
175175
})
@@ -261,80 +261,80 @@ describe('Directive', function () {
261261

262262
})
263263

264-
describe('.applyFilters()', function () {
264+
describe('.$applyFilters()', function () {
265265

266266
it('should work', function () {
267267
var d = build('text', 'abc | pluralize item | capitalize', compiler),
268-
v = d.applyFilters(2)
268+
v = d.$applyFilters(2)
269269
assert.strictEqual(v, 'Items')
270270
})
271271

272272
})
273273

274-
describe('.update()', function () {
274+
describe('.$update()', function () {
275275

276276
var d = build('text', 'abc', compiler),
277277
updated = false
278-
d._update = function () {
278+
d.update = function () {
279279
updated = true
280280
}
281281

282-
it('should call _update() for first time update, even with undefined', function () {
283-
d.update(undefined, true)
282+
it('should call user update() for first time update, even with undefined', function () {
283+
d.$update(undefined, true)
284284
assert.strictEqual(updated, true)
285285
})
286286

287-
it('should _update() when a different value is given', function () {
287+
it('should user update() when a different value is given', function () {
288288
updated = false
289-
d.update(123)
289+
d.$update(123)
290290
assert.strictEqual(d.value, 123)
291291
assert.strictEqual(updated, true)
292292
})
293293

294-
it('should not _update() if the value is the same', function () {
294+
it('should not call user update() if the value is the same', function () {
295295
updated = false
296-
d.update(123)
296+
d.$update(123)
297297
assert.ok(!updated)
298298
})
299299

300-
it('should call applyFilter() is there are filters', function () {
300+
it('should call $applyFilter() is there are filters', function () {
301301
var filterApplied = false
302302
d.filters = []
303-
d.applyFilters = function () {
303+
d.$applyFilters = function () {
304304
filterApplied = true
305305
}
306-
d.update(234)
306+
d.$update(234)
307307
assert.ok(filterApplied)
308308
})
309309

310310
})
311311

312-
describe('.unbind()', function () {
312+
describe('.$unbind()', function () {
313313

314314
var d = build('text', 'abc', compiler),
315315
unbound = false,
316316
val
317-
d._unbind = function (v) {
317+
d.unbind = function (v) {
318318
val = v
319319
unbound = true
320320
}
321321

322322
it('should not work if it has no element yet', function () {
323323
d.el = null
324-
d.unbind()
324+
d.$unbind()
325325
assert.strictEqual(unbound, false)
326326
})
327327

328-
it('should call _unbind() and null everything if it has an element', function () {
328+
it('should call user unbind() and null everything if it has an element', function () {
329329
d.el = true
330-
d.unbind()
330+
d.$unbind()
331331
assert.strictEqual(unbound, true)
332332
assert.ok(d.el === null && d.vm === null && d.binding === null && d.compiler === null)
333333
})
334334

335335
it('should not execute if called more than once', function () {
336336
unbound = false
337-
d.unbind()
337+
d.$unbind()
338338
assert.notOk(unbound)
339339
})
340340

test/unit/specs/viewmodel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ describe('ViewModel', function () {
417417
compiler: null,
418418
dirs: []
419419
},
420-
unbind: function () {
420+
$unbind: function () {
421421
dirUnbindCalled = true
422422
}
423423
}

0 commit comments

Comments
 (0)