Skip to content

Commit d1bd994

Browse files
committed
Cache animations
1 parent 2d4121e commit d1bd994

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/core/core.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ export default class Config {
248248
*/
249249
createResolver(scopes, context, prefixes = ['']) {
250250
const resolver = _createResolver(scopes, prefixes);
251-
return context
251+
return context && needContext(resolver, Object.getOwnPropertyNames(resolver))
252252
? _attachContext(resolver, isFunction(context) ? context() : context)
253253
: resolver;
254254
}

src/core/core.datasetController.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,12 @@ export default class DatasetController {
793793
_resolveAnimations(index, mode, active) {
794794
const me = this;
795795
const chart = me.chart;
796+
const cache = me._cachedDataOpts;
797+
const cacheKey = 'animation-' + mode;
798+
const cached = cache[cacheKey];
799+
if (cached) {
800+
return cached;
801+
}
796802
let options;
797803
if (chart.options.animation !== false) {
798804
const config = me.chart.config;
@@ -801,7 +807,11 @@ export default class DatasetController {
801807
const context = () => me.getContext(index, active, mode);
802808
options = config.createResolver(scopes, context);
803809
}
804-
return new Animations(chart, options && options[mode] || options);
810+
const animations = new Animations(chart, options && options[mode] || options);
811+
if (options._cacheable) {
812+
cache[cacheKey] = animations && Object.freeze(animations);
813+
}
814+
return animations;
805815
}
806816

807817
/**

src/helpers/helpers.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {defined, isArray, isFunction, isObject, resolveObjectKey, _capitalize} f
1010
export function _createResolver(scopes, prefixes = ['']) {
1111
const cache = {
1212
[Symbol.toStringTag]: 'Object',
13+
_cacheable: true,
1314
_scopes: scopes
1415
};
1516
return new Proxy(cache, {
@@ -42,6 +43,7 @@ export function _createResolver(scopes, prefixes = ['']) {
4243
*/
4344
export function _attachContext(proxy, context, subProxy) {
4445
const cache = {
46+
_cacheable: false,
4547
_proxy: proxy,
4648
_context: context,
4749
_subProxy: subProxy,

0 commit comments

Comments
 (0)