- commit
- 0f6e95e
- parent
- bd72fb5
- author
- Eric Bower
- date
- 2023-12-12 17:27:11 +0000 UTC
feat(slice.table): return empty value provided for reuse
2 files changed,
+4,
-0
+2,
-0
1@@ -118,6 +118,7 @@ it(tests, "with empty", async () => {
2 initialState,
3 });
4
5+ asserts.assertEquals(tbl.empty, first);
6 await store.run(function* () {
7 yield* updateStore(tbl.set({ [first.id]: first }));
8 });
9@@ -135,6 +136,7 @@ it(tests, "with no empty", async () => {
10 initialState,
11 });
12
13+ asserts.assertEquals(tbl.empty, undefined);
14 await store.run(function* () {
15 yield* updateStore(tbl.set({ [first.id]: first }));
16 });
+2,
-0
1@@ -85,6 +85,7 @@ export interface TableOutput<
2 > extends BaseSchema<Record<IdProp, Entity>> {
3 schema: "table";
4 initialState: Record<IdProp, Entity>;
5+ empty: Empty;
6 add: (e: Record<IdProp, Entity>) => (s: S) => void;
7 set: (e: Record<IdProp, Entity>) => (s: S) => void;
8 remove: (ids: IdProp[]) => (s: S) => void;
9@@ -140,6 +141,7 @@ export function createTable<
10 schema: "table",
11 name: name as string,
12 initialState,
13+ empty: typeof empty === "function" ? empty() : empty,
14 add: (entities) => (s) => {
15 const state = selectors.selectTable(s);
16 Object.keys(entities).forEach((id) => {