Skip to content

Commit de966f6

Browse files
committed
test and change doc for vm.$compile
1 parent 22d2bdf commit de966f6

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

changes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ By default, all child components **DO NOT** inherit the parent scope. Only anony
270270
vm.$log('item') // logs vm.item
271271
```
272272

273+
- `vm.$compile`
274+
275+
Partially compile a piece of DOM (Element or DocumentFragment). Returns a "decompile" function that tearsdown the directives created during the process. Note the decompile function does not remove the DOM. This method is exposed primarily for writing advanced custom directives.
276+
273277
## Computed Properties API Change
274278

275279
> Breaking

test/unit/specs/api/lifecycle_spec.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,5 +257,34 @@ if (_.inBrowser) {
257257

258258
})
259259

260+
describe('$compile', function () {
261+
262+
it('should partial compile and teardown stuff', function (done) {
263+
var el = document.createElement('div')
264+
var vm = new Vue({
265+
el: el,
266+
template: '{{a}}',
267+
data: {
268+
a: 'hi'
269+
}
270+
})
271+
expect(vm._directives.length).toBe(1)
272+
var partial = document.createElement('span')
273+
partial.textContent = '{{a}}'
274+
var decompile = vm.$compile(partial)
275+
expect(partial.textContent).toBe('hi')
276+
expect(vm._directives.length).toBe(2)
277+
decompile()
278+
expect(vm._directives.length).toBe(1)
279+
vm.a = 'ha'
280+
_.nextTick(function () {
281+
expect(el.textContent).toBe('ha')
282+
expect(partial.textContent).toBe('hi')
283+
done()
284+
})
285+
})
286+
287+
})
288+
260289
})
261290
}

0 commit comments

Comments
 (0)