Use a constructor to create the execute cache objects

This commit is contained in:
Michael "Z" Goddard 2018-05-04 12:33:42 -04:00
parent a9a23ef589
commit 9b82530f51
No known key found for this signature in database
GPG key ID: 762CD40DD5349872
2 changed files with 32 additions and 10 deletions

View file

@ -876,21 +876,22 @@ class Blocks {
* @param {string} blockId blockId for the desired execute cache
* @return {object} execute cache object
*/
BlocksExecuteCache.getCached = function (blocks, blockId) {
const block = blocks.getBlock(blockId);
if (typeof block === 'undefined') return null;
BlocksExecuteCache.getCached = function (blocks, blockId, CacheType = Object) {
let cached = blocks._cache._executeCached[blockId];
if (typeof cached !== 'undefined') {
return cached;
}
cached = {
const block = blocks.getBlock(blockId);
if (typeof block === 'undefined') return null;
cached = new CacheType({
_initialized: false,
opcode: blocks.getOpcode(block),
fields: blocks.getFields(block),
inputs: blocks.getInputs(block),
mutation: blocks.getMutation(block)
};
});
blocks._cache._executeCached[blockId] = cached;
return cached;
};