BlockCached instances are always initialized

This commit is contained in:
Michael "Z" Goddard 2018-05-07 10:31:28 -04:00
parent 5fd749918f
commit 2db2287d12
No known key found for this signature in database
GPG key ID: 762CD40DD5349872
2 changed files with 114 additions and 126 deletions

View file

@ -874,9 +874,10 @@ class Blocks {
* reset.
* @param {Blocks} blocks Blocks containing the expected blockId
* @param {string} blockId blockId for the desired execute cache
* @param {function} CacheType constructor for cached block information
* @return {object} execute cache object
*/
BlocksExecuteCache.getCached = function (blocks, blockId, CacheType = Object) {
BlocksExecuteCache.getCached = function (blocks, blockId, CacheType) {
let cached = blocks._cache._executeCached[blockId];
if (typeof cached !== 'undefined') {
return cached;
@ -885,13 +886,22 @@ BlocksExecuteCache.getCached = function (blocks, blockId, CacheType = Object) {
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)
});
if (typeof CacheType === 'undefined') {
cached = {
opcode: blocks.getOpcode(block),
fields: blocks.getFields(block),
inputs: blocks.getInputs(block),
mutation: blocks.getMutation(block)
};
} else {
cached = new CacheType(blocks, {
opcode: blocks.getOpcode(block),
fields: blocks.getFields(block),
inputs: blocks.getInputs(block),
mutation: blocks.getMutation(block)
});
}
blocks._cache._executeCached[blockId] = cached;
return cached;
};