.map NPE is gone, now I need to fix mocks
parent
6e4f5fe7ac
commit
f07d63fd5d
|
@ -6,8 +6,9 @@ import {
|
|||
TaggedResource,
|
||||
} from "farmbot";
|
||||
import * as _ from "lodash";
|
||||
import { resourceReducer, emptyState } from "../resources/reducer";
|
||||
import { resourceReducer } from "../resources/reducer";
|
||||
import { resourceReady } from "../sync/actions";
|
||||
import { emptyState } from "../resources/reducer";
|
||||
export function fakeDevice(): TaggedDevice {
|
||||
return {
|
||||
"kind": "Device",
|
||||
|
|
|
@ -11,8 +11,6 @@ import {
|
|||
updateNO, destroyOK, destroyNO, GeneralizedError, saveOK
|
||||
} from "../resources/actions";
|
||||
import { UnsafeError } from "../interfaces";
|
||||
import { findByUuid } from "../resources/reducer_support";
|
||||
// import { generateUuid } from "../resources/util";
|
||||
import { defensiveClone, unpackUUID } from "../util";
|
||||
import { EditResourceParams } from "./interfaces";
|
||||
import { ResourceIndex } from "../resources/interfaces";
|
||||
|
@ -23,6 +21,7 @@ import { maybeStartTracking } from "./maybe_start_tracking";
|
|||
import { t } from "i18next";
|
||||
import { newTaggedResource } from "../sync/actions";
|
||||
import { arrayUnwrap } from "../resources/util";
|
||||
import { findByUuid } from "../resources/reducer_support";
|
||||
|
||||
export function edit(tr: TaggedResource, changes: Partial<typeof tr.body>):
|
||||
ReduxAction<EditResourceParams> {
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
import { Edge } from "./interfaces";
|
||||
/** throttle calls to these functions to avoid unnecessary re-paints. */
|
||||
const SLOWDOWN_TIME = 1500;
|
||||
// import { Edge } from "./interfaces";
|
||||
// /** throttle calls to these functions to avoid unnecessary re-paints. */
|
||||
// const SLOWDOWN_TIME = 1500;
|
||||
|
||||
const lastCalledAt: Record<Edge, number> = {
|
||||
"user.api": 0, "user.mqtt": 0, "bot.mqtt": 0
|
||||
};
|
||||
// const lastCalledAt: Record<Edge, number> = {
|
||||
// "user.api": 0, "user.mqtt": 0, "bot.mqtt": 0
|
||||
// };
|
||||
|
||||
export function bumpThrottle(edge: Edge, now: number) {
|
||||
lastCalledAt[edge] = now;
|
||||
}
|
||||
// export function bumpThrottle(edge: Edge, now: number) {
|
||||
// lastCalledAt[edge] = now;
|
||||
// }
|
||||
|
||||
export function shouldThrottle(edge: Edge, now: number): boolean {
|
||||
const then = lastCalledAt[edge];
|
||||
const diff = then - now;
|
||||
// export function shouldThrottle(edge: Edge, now: number): boolean {
|
||||
// const then = lastCalledAt[edge];
|
||||
// const diff = then - now;
|
||||
|
||||
return diff > SLOWDOWN_TIME;
|
||||
}
|
||||
// return diff > SLOWDOWN_TIME;
|
||||
// }
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import { findByUuid, joinKindAndId } from "../reducer_support";
|
||||
import { fakeState } from "../../__test_support__/fake_state";
|
||||
import { overwrite, refreshStart, refreshOK, refreshNO } from "../../api/crud";
|
||||
import {
|
||||
|
@ -14,6 +13,7 @@ import { GeneralizedError } from "../actions";
|
|||
import { Actions } from "../../constants";
|
||||
import { fakeResource } from "../../__test_support__/fake_resource";
|
||||
import { resourceReducer } from "../reducer";
|
||||
import { joinKindAndId, findByUuid } from "../reducer_support";
|
||||
import { resourceReady } from "../../sync/actions";
|
||||
import { EditResourceParams } from "../../api/interfaces";
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { lookupReducer } from "../resource_index_chain";
|
||||
import { lookupReducer } from "../reducer_support";
|
||||
|
||||
describe("variableLookupTable", () => {
|
||||
it("creates variable meta data", () => {
|
||||
|
|
|
@ -13,7 +13,8 @@ import {
|
|||
fakeSequence
|
||||
} from "../../__test_support__/fake_state/resources";
|
||||
import * as _ from "lodash";
|
||||
import { resourceReducer, emptyState } from "../reducer";
|
||||
import { resourceReducer } from "../reducer";
|
||||
import { emptyState } from "../reducer";
|
||||
import { resourceReady, newTaggedResource } from "../../sync/actions";
|
||||
// import { Actions } from "../../constants";
|
||||
|
||||
|
|
|
@ -1,41 +1,25 @@
|
|||
import { SpecialStatus, TaggedResource } from "farmbot";
|
||||
import { merge } from "lodash";
|
||||
import { EditResourceParams } from "../api/interfaces";
|
||||
import { Actions } from "../constants";
|
||||
import { farmwareState } from "../farmware/reducer";
|
||||
import { initialState as designerState } from "../farm_designer/reducer";
|
||||
import { initialState as helpState } from "../help/reducer";
|
||||
import { generateReducer } from "../redux/generate_reducer";
|
||||
import { RestResources } from "./interfaces";
|
||||
import {
|
||||
indexUpsert,
|
||||
mutateSpecialStatus,
|
||||
findByUuid,
|
||||
indexRemove,
|
||||
initResourceReducer,
|
||||
afterEach
|
||||
} from "./reducer_support";
|
||||
import { TaggedResource, SpecialStatus } from "farmbot";
|
||||
import { Actions } from "../constants";
|
||||
import { EditResourceParams } from "../api/interfaces";
|
||||
import { defensiveClone, equals } from "../util";
|
||||
import { merge } from "lodash";
|
||||
import { SyncBodyContents } from "../sync/actions";
|
||||
import { GeneralizedError } from "./actions";
|
||||
import { initialState as helpState } from "../help/reducer";
|
||||
import { initialState as designerState } from "../farm_designer/reducer";
|
||||
import { farmwareState } from "../farmware/reducer";
|
||||
import { initialState as regimenState } from "../regimens/reducer";
|
||||
import { initialState as sequenceState } from "../sequences/reducer";
|
||||
import { SyncBodyContents } from "../sync/actions";
|
||||
import { defensiveClone, equals } from "../util";
|
||||
import { GeneralizedError } from "./actions";
|
||||
import { ResourceIndex, RestResources } from "./interfaces";
|
||||
import {
|
||||
afterEach,
|
||||
findByUuid,
|
||||
initResourceReducer,
|
||||
mutateSpecialStatus
|
||||
} from "./reducer_support";
|
||||
import { INDEXES } from "./resource_index_chain";
|
||||
import { arrayWrap } from "./util";
|
||||
|
||||
const ups = INDEXES.map(x => x.up);
|
||||
|
||||
export function indexUpsert(db: ResourceIndex, resources: TaggedResource) {
|
||||
ups.map(callback => {
|
||||
arrayWrap(resources).map(resource => callback(resource, db));
|
||||
});
|
||||
}
|
||||
|
||||
const downs = INDEXES.map(x => x.down).reverse();
|
||||
|
||||
export function indexRemove(db: ResourceIndex, resources: TaggedResource) {
|
||||
downs.map(callback => {
|
||||
arrayWrap(resources).map(resource => callback(resource, db));
|
||||
});
|
||||
}
|
||||
|
||||
export const emptyState = (): RestResources => {
|
||||
return {
|
||||
|
|
|
@ -1,14 +1,88 @@
|
|||
import { ResourceName, SpecialStatus, TaggedResource } from "farmbot";
|
||||
import {
|
||||
ResourceName,
|
||||
ScopeDeclarationBodyItem,
|
||||
SpecialStatus,
|
||||
TaggedResource,
|
||||
TaggedSequence
|
||||
} from "farmbot";
|
||||
import { combineReducers } from "redux";
|
||||
import { farmwareReducer as farmware } from "../farmware/reducer";
|
||||
import { designer as farm_designer } from "../farm_designer/reducer";
|
||||
import { helpReducer as help } from "../help/reducer";
|
||||
import { ReduxAction } from "../redux/interfaces";
|
||||
import { helpReducer as help } from "../help/reducer";
|
||||
import { designer as farm_designer } from "../farm_designer/reducer";
|
||||
import { farmwareReducer as farmware } from "../farmware/reducer";
|
||||
import { regimensReducer as regimens } from "../regimens/reducer";
|
||||
import { sequenceReducer as sequences } from "../sequences/reducer";
|
||||
import { ResourceIndex, RestResources } from "./interfaces";
|
||||
import { indexUpsert } from "./reducer";
|
||||
import { sanitizeNodes } from "../sequences/step_tiles/tile_move_absolute/variables_support";
|
||||
import { ResourceIndex, RestResources, VariableNameMapping } from "./interfaces";
|
||||
import { isTaggedResource } from "./tagged_resources";
|
||||
import { arrayWrap } from "./util";
|
||||
|
||||
type IndexDirection = "up" | "down";
|
||||
type IndexerCallback = (self: TaggedResource, index: ResourceIndex) => void;
|
||||
export interface Indexer extends Record<IndexDirection, IndexerCallback> { }
|
||||
|
||||
const REFERENCES: Indexer = {
|
||||
up: (r, i) => i.references[r.uuid] = r,
|
||||
down: (r, i) => delete i.references[r.uuid],
|
||||
};
|
||||
|
||||
const ALL: Indexer = {
|
||||
up: (r, s) => s.all[r.uuid] = true,
|
||||
down: (r, i) => delete i.all[r.uuid],
|
||||
};
|
||||
|
||||
const BY_KIND: Indexer = {
|
||||
up: (r, i) => i.byKind[r.kind][r.uuid] = r.uuid,
|
||||
down(r, i) {
|
||||
const byKind = i.byKind[r.kind];
|
||||
delete byKind[r.uuid];
|
||||
},
|
||||
};
|
||||
|
||||
const BY_KIND_AND_ID: Indexer = {
|
||||
up: (r, i) => {
|
||||
if (r.body.id) {
|
||||
i.byKindAndId[joinKindAndId(r.kind, r.body.id)] = r.uuid;
|
||||
}
|
||||
},
|
||||
down(r, i) {
|
||||
delete i.byKindAndId[joinKindAndId(r.kind, r.body.id)];
|
||||
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*/ };
|
||||
};
|
||||
|
||||
export function variableLookupTable(tr: TaggedSequence): VariableNameMapping {
|
||||
return (tr.body.args.locals.body || []).reduce(lookupReducer, {});
|
||||
}
|
||||
|
||||
const SEQUENCE_STUFF: Indexer = {
|
||||
up(r, i) {
|
||||
if (r.kind === "Sequence") {
|
||||
const tr = { ...r, body: sanitizeNodes(r.body) };
|
||||
i.references[r.uuid] = tr;
|
||||
i.sequenceMeta[r.uuid] = variableLookupTable(tr);
|
||||
}
|
||||
},
|
||||
down(r, i) {
|
||||
delete i.sequenceMeta[r.uuid];
|
||||
},
|
||||
};
|
||||
|
||||
export const INDEXES: Indexer[] = [
|
||||
REFERENCES,
|
||||
ALL,
|
||||
BY_KIND,
|
||||
BY_KIND_AND_ID,
|
||||
SEQUENCE_STUFF,
|
||||
];
|
||||
|
||||
export function joinKindAndId(kind: ResourceName, id: number | undefined) {
|
||||
return `${kind}.${id || 0}`;
|
||||
|
@ -66,3 +140,19 @@ export function whoops(origin: string, kind: string): never {
|
|||
const msg = `${origin}/${kind}: No handler written for this one yet.`;
|
||||
throw new Error(msg);
|
||||
}
|
||||
|
||||
const ups = INDEXES.map(x => x.up);
|
||||
|
||||
export function indexUpsert(db: ResourceIndex, resources: TaggedResource) {
|
||||
ups.map(callback => {
|
||||
arrayWrap(resources).map(resource => callback(resource, db));
|
||||
});
|
||||
}
|
||||
|
||||
const downs = INDEXES.map(x => x.down).reverse();
|
||||
|
||||
export function indexRemove(db: ResourceIndex, resources: TaggedResource) {
|
||||
downs.map(callback => {
|
||||
arrayWrap(resources).map(resource => callback(resource, db));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
import { ResourceIndex, VariableNameMapping } from "./interfaces";
|
||||
import { TaggedResource, TaggedSequence, ScopeDeclarationBodyItem } from "farmbot";
|
||||
import { joinKindAndId } from "./reducer_support";
|
||||
import {
|
||||
sanitizeNodes
|
||||
} from "../sequences/step_tiles/tile_move_absolute/variables_support";
|
||||
|
||||
type IndexDirection = "up" | "down";
|
||||
type IndexerCallback = (self: TaggedResource, index: ResourceIndex) => void;
|
||||
export interface Indexer extends Record<IndexDirection, IndexerCallback> { }
|
||||
|
||||
const REFERENCES: Indexer = {
|
||||
up: (r, i) => i.references[r.uuid] = r,
|
||||
down: (r, i) => delete i.references[r.uuid],
|
||||
};
|
||||
|
||||
const ALL: Indexer = {
|
||||
up: (r, s) => s.all[r.uuid] = true,
|
||||
down: (r, i) => delete i.all[r.uuid],
|
||||
};
|
||||
|
||||
const BY_KIND: Indexer = {
|
||||
up: (r, i) => i.byKind[r.kind][r.uuid] = r.uuid,
|
||||
down(r, i) {
|
||||
const byKind = i.byKind[r.kind];
|
||||
delete byKind[r.uuid];
|
||||
},
|
||||
};
|
||||
|
||||
const BY_KIND_AND_ID: Indexer = {
|
||||
up: (r, i) => {
|
||||
if (r.body.id) {
|
||||
i.byKindAndId[joinKindAndId(r.kind, r.body.id)] = r.uuid;
|
||||
}
|
||||
},
|
||||
down(r, i) {
|
||||
delete i.byKindAndId[joinKindAndId(r.kind, r.body.id)];
|
||||
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*/ };
|
||||
};
|
||||
|
||||
export function variableLookupTable(tr: TaggedSequence): VariableNameMapping {
|
||||
return (tr.body.args.locals.body || []).reduce(lookupReducer, {});
|
||||
}
|
||||
|
||||
const SEQUENCE_STUFF: Indexer = {
|
||||
up(r, i) {
|
||||
if (r.kind === "Sequence") {
|
||||
const tr = { ...r, body: sanitizeNodes(r.body) };
|
||||
i.references[r.uuid] = tr;
|
||||
i.sequenceMeta[r.uuid] = variableLookupTable(tr);
|
||||
}
|
||||
},
|
||||
down(r, i) {
|
||||
delete i.sequenceMeta[r.uuid];
|
||||
},
|
||||
};
|
||||
|
||||
export const INDEXES: Indexer[] = [
|
||||
REFERENCES,
|
||||
ALL,
|
||||
BY_KIND,
|
||||
BY_KIND_AND_ID,
|
||||
SEQUENCE_STUFF,
|
||||
];
|
|
@ -1,6 +1,5 @@
|
|||
import * as _ from "lodash";
|
||||
import { ResourceIndex } from "./interfaces";
|
||||
import { joinKindAndId } from "./reducer_support";
|
||||
import {
|
||||
ResourceName,
|
||||
TaggedGenericPointer,
|
||||
|
@ -26,6 +25,7 @@ import { betterCompact, bail } from "../util";
|
|||
import { findAllById } from "./selectors_by_id";
|
||||
import { findPoints, selectAllPoints, selectAllActivePoints } from "./selectors_by_kind";
|
||||
import { assertUuid } from "./util";
|
||||
import { joinKindAndId } from "./reducer_support";
|
||||
|
||||
export * from "./selectors_by_id";
|
||||
export * from "./selectors_by_kind";
|
||||
|
|
|
@ -16,10 +16,10 @@ import {
|
|||
TaggedToolSlotPointer,
|
||||
} from "farmbot";
|
||||
import { ResourceIndex } from "./interfaces";
|
||||
import { joinKindAndId } from "./reducer_support";
|
||||
import { isNumber } from "lodash";
|
||||
import { findAll } from "./selectors";
|
||||
import * as _ from "lodash";
|
||||
import { joinKindAndId } from "./reducer_support";
|
||||
|
||||
/** FINDS: all tagged resources with particular ID */
|
||||
export const findAllById =
|
||||
|
|
|
@ -31,8 +31,8 @@ import {
|
|||
} from "./tagged_resources";
|
||||
import { sortResourcesById, betterCompact, bail } from "../util";
|
||||
import { error } from "farmbot-toastr";
|
||||
import { joinKindAndId } from "./reducer_support";
|
||||
import { assertUuid } from "./util";
|
||||
import { joinKindAndId } from "./reducer_support";
|
||||
|
||||
const isSaved = <T extends TaggedResource>(t: T) =>
|
||||
t.specialStatus === SpecialStatus.SAVED;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { ResourceName } from "farmbot";
|
||||
import { joinKindAndId } from "./reducer_support";
|
||||
import { Dictionary } from "farmbot/dist";
|
||||
import { betterCompact } from "../util";
|
||||
import * as _ from "lodash";
|
||||
import { ResourceIndex } from "./interfaces";
|
||||
import { joinKindAndId } from "./reducer_support";
|
||||
|
||||
let count = 0;
|
||||
export function generateUuid(id: number | undefined, kind: ResourceName) {
|
||||
|
|
|
@ -12,10 +12,10 @@ import {
|
|||
} from "farmbot";
|
||||
import { ReadPin, AllowedPinTypes, NamedPin } from "farmbot";
|
||||
import { bail } from "../../util/errors";
|
||||
import { joinKindAndId } from "../../resources/reducer_support";
|
||||
import { StepParams } from "../interfaces";
|
||||
import { editStep } from "../../api/crud";
|
||||
import { ShouldDisplay, Feature } from "../../devices/interfaces";
|
||||
import { joinKindAndId } from "../../resources/reducer_support";
|
||||
|
||||
/** `headingIds` required to group the four kinds of pins. */
|
||||
export enum PinGroupName {
|
||||
|
|
|
@ -11,8 +11,8 @@ import { Vector3 } from "farmbot/dist";
|
|||
import { TOOL } from "./interfaces";
|
||||
import * as _ from "lodash";
|
||||
import { t } from "i18next";
|
||||
import { joinKindAndId } from "../../../resources/reducer_support";
|
||||
import { capitalize } from "lodash";
|
||||
import { joinKindAndId } from "../../../resources/reducer_support";
|
||||
|
||||
export function activeTools(resources: ResourceIndex) {
|
||||
const Tool: TaggedTool["kind"] = "Tool";
|
||||
|
|
Loading…
Reference in New Issue