Fix stack overflow (oops)

pull/1027/head
Rick Carlino 2018-10-30 16:32:17 -05:00
parent 01941e51c1
commit 9784828e64
3 changed files with 16 additions and 12 deletions

View File

@ -9,13 +9,13 @@ import { Everything } from "../../../interfaces";
import { ToggleDayParams } from "../interfaces";
import { error, warning } from "farmbot-toastr";
import { newTaggedResource } from "../../../sync/actions";
import { arrayUnwrap } from "../../../resources/util";
describe("commitBulkEditor()", () => {
function newFakeState() {
const state = fakeState();
const fakeResources: TaggedResource[] = [
...newTaggedResource("Regimen", {
arrayUnwrap(newTaggedResource("Regimen", {
"id": 1,
"name": "Test Regimen",
"color": "gray",
@ -27,8 +27,8 @@ describe("commitBulkEditor()", () => {
"time_offset": 1000
}
]
}),
...newTaggedResource("Sequence", {
})),
arrayUnwrap(newTaggedResource("Sequence", {
"id": 1,
"name": "Test Sequence",
"color": "gray",
@ -38,7 +38,7 @@ describe("commitBulkEditor()", () => {
"version": 4
},
"kind": "sequence"
})
}))
];
state.resources.index = buildResourceIndex(fakeResources).index;
const regimenUuid = state.resources.index.all[0];

View File

@ -14,7 +14,7 @@ export interface Indexer extends Record<IndexDirection, IndexerCallback> { }
// be using Record<T, U> types.
const filterOutUuid = (tr: TaggedResource) => (id: string) => id !== tr.uuid;
const REFERENCES: Indexer = { // ========
const REFERENCES: Indexer = {
up(r, i) { i.references[r.uuid] = r; },
down(r, i) { delete i.references[r.uuid]; },
};

View File

@ -1,9 +1,9 @@
import axios from "axios";
import { API } from "../api";
import { Actions } from "../constants";
import { TaggedResource as TR, SpecialStatus } from "farmbot";
import { TaggedResource as TR, SpecialStatus, TaggedResource } from "farmbot";
import { Session } from "../session";
import { arrayWrap } from "../resources/util";
import { arrayWrap, generateUuid } from "../resources/util";
export interface SyncBodyContents<T extends TR> {
kind: T["kind"];
@ -25,10 +25,14 @@ export const resourceReady =
export const newTaggedResource = <T extends TR>(kind: T["kind"],
bodies: T["body"] | T["body"][],
specialStatus = SpecialStatus.SAVED): T[] => {
return arrayWrap(bodies).map((body: T["body"]): T => {
const tr = newTaggedResource(kind, body)[0];
tr.specialStatus = specialStatus;
return tr;
const arr = arrayWrap(bodies);
return arr.map((body: T["body"]): T => {
return {
kind: kind as TaggedResource["kind"],
body: body as TaggedResource["body"],
uuid: generateUuid(body && body.id ? body.id : undefined, kind),
specialStatus
} as T;
});
};