Skip to content

Commit 8028bd9

Browse files
committed
Implement per-h cache
Keep the API backwards compatible by redefining htm.bind.
1 parent 935e8b1 commit 8028bd9

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/index.mjs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@
1414
import { MINI } from './constants.mjs';
1515
import { build, evaluate } from './build.mjs';
1616

17-
const CACHE = new Map();
17+
const regular = h => {
18+
const cache = new Map();
1819

19-
const cached = function(statics) {
20-
let tmp = CACHE.get(statics);
21-
if (!tmp) {
22-
CACHE.set(statics, tmp = build(statics));
23-
}
24-
tmp = evaluate(this, tmp, arguments, []);
25-
return tmp.length > 1 ? tmp : tmp[0];
20+
return function(statics) {
21+
let tmp = cache.get(statics);
22+
if (!tmp) {
23+
cache.set(statics, tmp = build(statics));
24+
}
25+
tmp = evaluate(h, tmp, arguments, []);
26+
return tmp.length > 1 ? tmp : tmp[0];
27+
};
2628
};
2729

28-
export default MINI ? build : cached;
30+
export default MINI ? build : { bind: regular };

0 commit comments

Comments
 (0)