improve some comments, remove unused properties from magic state shim in node API

This commit is contained in:
d98762625 2020-06-12 12:35:33 +01:00
parent 53e69835ff
commit 4dafa50799
4 changed files with 16 additions and 15 deletions

View file

@ -24,8 +24,11 @@ class NodeRecipe {
/**
* Validate an ingredient $ coerce to operation if necessary.
* Validate an ingredient & coerce to operation if necessary.
* @param {String | Function | Object} ing
* @returns {Function || Object} The operation, or an object with the
* operation and its arguments
* @throws {TypeError} If it cannot find the operation in chef's list of operations.
*/
_validateIngredient(ing) {
// CASE operation name given. Find operation and validate
@ -34,6 +37,7 @@ class NodeRecipe {
return sanitise(op.opName) === sanitise(ing);
});
if (op) {
// Need to validate against case 2
return this._validateIngredient(op);
} else {
throw new TypeError(`Couldn't find an operation with name '${ing}'.`);
@ -41,7 +45,7 @@ class NodeRecipe {
// CASE operation given. Check its a chef operation and check its not flowcontrol
} else if (typeof ing === "function") {
if (ing.flowControl) {
throw new TypeError(`flowControl operations like ${ing.opName} are not currently allowed in recipes for chef.bake`);
throw new TypeError(`flowControl operations like ${ing.opName} are not currently allowed in recipes for chef.bake in the Node API`);
}
if (operations.includes(ing)) {
@ -63,7 +67,7 @@ class NodeRecipe {
/**
* Parse config for recipe.
* Parse an opList from a recipeConfig and assign it to the recipe's opList.
* @param {String | Function | String[] | Function[] | [String | Function]} recipeConfig
*/
_parseConfig(recipeConfig) {

View file

@ -194,17 +194,14 @@ export function _wrap(OpClass) {
const {transformedInput, transformedArgs} = prepareOp(opInstance, input, args);
// SPECIAL CASE for Magic. Other flowControl operations will
// not work because the opList is not passed through.
// not work because the opList is not passed in.
if (isFlowControl) {
opInstance.ingValues = transformedArgs;
const state = {
"progress": 0,
"dish": ensureIsDish(transformedInput),
"opList": [opInstance],
"numJumps": 0,
"numRegisters": 0,
"forkOffset": 0
progress: 0,
dish: ensureIsDish(transformedInput),
opList: [opInstance],
};
const updatedState = await opInstance.run(state);