Revert "Revert "Push reported""

This reverts commit 107adad647.
This commit is contained in:
Michael "Z" Goddard 2018-04-10 16:29:51 -04:00
parent 5b9dc4df77
commit d04d6b2c6a
No known key found for this signature in database
GPG key ID: 762CD40DD5349872
8 changed files with 198 additions and 65 deletions

View file

@ -4,6 +4,7 @@ const xmlEscape = require('../util/xml-escape');
const MonitorRecord = require('./monitor-record');
const Clone = require('../util/clone');
const {Map} = require('immutable');
const BlocksExecuteCache = require('./blocks-execute-cache');
/**
* @fileoverview
@ -47,7 +48,14 @@ class Blocks {
* Cache procedure definitions by block id
* @type {object.<string, ?string>}
*/
procedureDefinitions: {}
procedureDefinitions: {},
/**
* A cache for execute to use and store on. Only available to
* execute.
* @type {object.<string, object>}
*/
_executeCached: {}
};
}
@ -359,6 +367,7 @@ class Blocks {
this._cache.inputs = {};
this._cache.procedureParamNames = {};
this._cache.procedureDefinitions = {};
this._cache._executeCached = {};
}
/**
@ -435,7 +444,7 @@ class Blocks {
const isSpriteSpecific = optRuntime.monitorBlockInfo.hasOwnProperty(block.opcode) &&
optRuntime.monitorBlockInfo[block.opcode].isSpriteSpecific;
block.targetId = isSpriteSpecific ? optRuntime.getEditingTarget().id : null;
if (wasMonitored && !block.isMonitored) {
optRuntime.requestRemoveMonitor(block.id);
} else if (!wasMonitored && block.isMonitored) {
@ -859,4 +868,31 @@ class Blocks {
}
}
/**
* A private method shared with execute to build an object containing the block
* information execute needs and that is reset when other cached Blocks info is
* reset.
* @param {Blocks} blocks Blocks containing the expected blockId
* @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;
let cached = blocks._cache._executeCached[blockId];
if (typeof cached !== 'undefined') {
return cached;
}
cached = {
_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;
};
module.exports = Blocks;