Cleanup / docs
parent
136a2fe665
commit
0679c04e61
|
@ -316,14 +316,12 @@ export let FAKE_RESOURCES: TaggedResource[] = [tr1, fakeDevice(), tr2, tr3, tr4,
|
|||
tr5, tr6, tr7, tr8, tr9, tr10, tr11, tr12, tr13, tr14, tr15, log];
|
||||
const KIND: keyof TaggedResource = "kind"; // Safety first, kids.
|
||||
|
||||
export
|
||||
function buildResourceIndex(resources: TaggedResource[] = FAKE_RESOURCES,
|
||||
state = emptyState()) {
|
||||
const z = _(resources)
|
||||
export function buildResourceIndex(resources: TaggedResource[] = FAKE_RESOURCES,
|
||||
state = emptyState()) {
|
||||
return _(resources)
|
||||
.groupBy(KIND)
|
||||
.toPairs()
|
||||
.map((x: [TaggedResource["kind"], TaggedResource[]]) => x)
|
||||
.map(y => resourceReady(y[0], y[1]))
|
||||
.reduce(resourceReducer, state);
|
||||
return z;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ import { bot } from "../../__test_support__/fake_state/bot";
|
|||
import { auth } from "../../__test_support__/fake_state/token";
|
||||
import { buildResourceIndex } from "../../__test_support__/resource_index_builder";
|
||||
import { fakeRegimen } from "../../__test_support__/fake_state/resources";
|
||||
import { resourceUsageList } from "../../resources/in_use";
|
||||
|
||||
describe("<Regimens />", () => {
|
||||
function fakeProps(): Props {
|
||||
|
@ -33,12 +32,7 @@ describe("<Regimens />", () => {
|
|||
weeks: [],
|
||||
bot,
|
||||
calendar: [],
|
||||
regimenUsageStats: resourceUsageList({
|
||||
"Regimen.FarmEvent": {},
|
||||
"Regimen.Sequence": {},
|
||||
"Sequence.FarmEvent": {},
|
||||
"Sequence.Sequence": {},
|
||||
})
|
||||
regimenUsageStats: {}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -73,13 +73,15 @@ export interface ResourceIndex {
|
|||
* SOLUTION:
|
||||
* * Create an index entry, indexed by UUID, for every resource that is
|
||||
* "in_use".
|
||||
* * If it does not have an entry, it's not in use.
|
||||
* * If it does not have an entry, it's not in use and can safely be deleted.
|
||||
*
|
||||
* {
|
||||
* ...
|
||||
* // Two other resources have a "reservation" on Sequence.0.1
|
||||
* // (from SCENARIO above)
|
||||
* "Sequence.0.1": { "FarmEvent.0.2": true, "Sequence.0.3": true }
|
||||
* // Not in use by anything
|
||||
* "Sequence.0.5": undefined,
|
||||
* // Two other resources have a "reservation" on Sequence.0.1
|
||||
* "Sequence.0.1": { "FarmEvent.0.2": true, "Sequence.0.3": true }
|
||||
* ...
|
||||
* }
|
||||
*/
|
||||
|
|
|
@ -7,7 +7,6 @@ import {
|
|||
indexRemove,
|
||||
initResourceReducer,
|
||||
afterEach,
|
||||
// REINDEXERS
|
||||
} from "./reducer_support";
|
||||
import { TaggedResource, SpecialStatus } from "farmbot";
|
||||
import { Actions } from "../constants";
|
||||
|
@ -102,13 +101,7 @@ export let resourceReducer =
|
|||
!s.loaded.includes(payload.kind) && s.loaded.push(payload.kind);
|
||||
|
||||
payload.body.map(x => indexUpsert(s.index, x));
|
||||
// if (s.loaded.length > 22) {
|
||||
// const fn = REINDEXERS[payload.kind];
|
||||
// fn && fn(s.index);
|
||||
// }
|
||||
// if (s.loaded.length == 22) {
|
||||
// console.log("TODO");
|
||||
// }
|
||||
|
||||
return s;
|
||||
})
|
||||
.add<TaggedResource>(Actions.REFRESH_RESOURCE_OK, (s, { payload }) => {
|
||||
|
|
|
@ -128,22 +128,12 @@ export function reindexAllFarmEventUsage(i: ResourceIndex) {
|
|||
});
|
||||
}
|
||||
|
||||
const IN_USE: Indexer = {
|
||||
up: (_r, _i) => {
|
||||
// r.kind === "FarmEvent" && reindexAllFarmEventUsage(i);
|
||||
},
|
||||
down: (_r, _i) => {
|
||||
// r.kind === "FarmEvent" && reindexAllFarmEventUsage(i);
|
||||
}
|
||||
};
|
||||
|
||||
export const INDEXERS: Indexer[] = [
|
||||
REFERENCES,
|
||||
ALL,
|
||||
BY_KIND,
|
||||
BY_KIND_AND_ID,
|
||||
SEQUENCE_STUFF,
|
||||
IN_USE
|
||||
SEQUENCE_STUFF
|
||||
];
|
||||
|
||||
type Reindexer = (i: ResourceIndex) => void;
|
||||
|
|
Loading…
Reference in New Issue