CC: @gabrielBurnworth

pull/1036/head
Rick Carlino 2018-11-07 13:34:45 -06:00
parent 77244e3e61
commit 98c8d05875
3 changed files with 26 additions and 7 deletions

View File

@ -0,0 +1,15 @@
import { lookupReducer } from "../resource_index_chain";
describe("variableLookupTable", () => {
it("creates variable meta data", () => {
// Bare minimum example. CC: @gabrielBurnworth
const result = lookupReducer({}, {
kind: "parameter_declaration",
args: {
label: "parent",
data_type: "Point"
}
});
expect(result).toBeDefined();
});
});

View File

@ -1,5 +1,5 @@
import { ResourceIndex, VariableNameMapping } from "./interfaces";
import { TaggedResource, TaggedSequence } from "farmbot";
import { TaggedResource, TaggedSequence, ScopeDeclarationBodyItem } from "farmbot";
import { joinKindAndId } from "./reducer_support";
import {
sanitizeNodes
@ -38,11 +38,17 @@ const BY_KIND_AND_ID: Indexer = {
delete i.byKindAndId[joinKindAndId(r.kind, 0)];
},
};
export const lookupReducer =
(_acc: VariableNameMapping, _item: ScopeDeclarationBodyItem) => {
// const { args } = item;
// const n = { [args.label]: { label: args.label } };
// @gabrielBurnworth I am stubbing this to just return {};
// (still crashes locally)
return { /*...acc, n*/ };
};
function variableLookupTable(tr: TaggedSequence): VariableNameMapping {
return (tr.body.args.locals.body || []).reduce((acc, { args }) => {
return { ...acc, [args.label]: { label: args.label } };
}, {} as VariableNameMapping); // WOW FUNCTIONAL PROGRAMMING
export function variableLookupTable(tr: TaggedSequence): VariableNameMapping {
return (tr.body.args.locals.body || []).reduce(lookupReducer, {});
}
const SEQUENCE_STUFF: Indexer = {

View File

@ -48,8 +48,6 @@ export class RefactoredExecuteBlock extends React.Component<ExecBlockParams, {}>
executor: (step: Execute) => {
if (_.isNumber(input.value)) {
step.args.sequence_id = input.value;
} else {
throw new Error("Never not a number;");
}
}
}));