Skip to content

Commit 9f37925

Browse files
committed
cache linker for v-ifs
1 parent 05933b0 commit 9f37925

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/cache.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function Cache (limit) {
1515
this.size = 0
1616
this.limit = limit
1717
this.head = this.tail = undefined
18-
this._keymap = {}
18+
this._keymap = Object.create(null)
1919
}
2020

2121
var p = Cache.prototype

src/directives/if.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ var _ = require('../util')
22
var compiler = require('../compiler')
33
var templateParser = require('../parsers/template')
44
var transition = require('../transition')
5+
var Cache = require('../cache')
6+
var cache = new Cache(1000)
57

68
module.exports = {
79

@@ -19,11 +21,16 @@ module.exports = {
1921
this.template.appendChild(templateParser.clone(el))
2022
}
2123
// compile the nested partial
22-
this.linker = compiler.compile(
23-
this.template,
24-
this.vm.$options,
25-
true
26-
)
24+
var cacheId = (this.vm.constructor.cid || '') + el.outerHTML
25+
this.linker = cache.get(cacheId)
26+
if (!this.linker) {
27+
this.linker = compiler.compile(
28+
this.template,
29+
this.vm.$options,
30+
true
31+
)
32+
cache.put(cacheId, this.linker)
33+
}
2734
} else {
2835
process.env.NODE_ENV !== 'production' && _.warn(
2936
'v-if="' + this.expression + '" cannot be ' +

0 commit comments

Comments
 (0)