Skip to content

Commit

Permalink
Depend on state
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Candeia <marrcooos@gmail.com>
  • Loading branch information
mcandeia committed Sep 8, 2023
1 parent 7be8549 commit f070210
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
6 changes: 3 additions & 3 deletions admin/fsStorage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Resolvable } from "deco/engine/core/resolver.ts";
import { newFsProvider } from "deco/engine/releases/fs.ts";
import {
OnChangeCallback,
ReadOptions,
Release,
OnChangeCallback,
ReadOptions,
Release,
} from "deco/engine/releases/provider.ts";
import { join } from "std/path/mod.ts";
import { BlockStore } from "./mod.ts";
Expand Down
4 changes: 3 additions & 1 deletion admin/loaders/blocks/listRevisions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export default async function ListRevisions(
_req: Request,
ctx: AppContext,
): Promise<Pagination<BlockState>> {
const block = await ctx.invoke["deco-sites/admin"].loaders.blocks.latest(props);
const block = await ctx.invoke["deco-sites/admin"].loaders.blocks.latest(
props,
);
if (!block) {
return {
data: [],
Expand Down
5 changes: 3 additions & 2 deletions admin/loaders/state.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { Resolvable } from "deco/engine/core/resolver.ts";
import { AppContext } from "../mod.ts";

export interface Props {
site: string;
blockId: string;
}

export type State = Record<string, any>;

export default async function Latest(
_props: unknown,
_req: Request,
ctx: AppContext,
): Promise<Record<string, Resolvable>> {
): Promise<State> {
return await ctx.storage.state();
}
9 changes: 7 additions & 2 deletions admin/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Resolvable } from "deco/engine/core/resolver.ts";
import { Release } from "deco/engine/releases/provider.ts";
import type { App, AppContext as AC } from "deco/mod.ts";
import { FsBlockStorage } from "./fsStorage.ts";
import { State as Resolvables } from "./loaders/state.ts";
import manifest, { Manifest } from "./manifest.gen.ts";

export const ANONYMOUS = "Anonymous";
Expand All @@ -24,13 +25,17 @@ export interface BlockState<TBlock = unknown> {
revision: string;
}

export interface Props {
resolvables: Resolvables;
}

/**
* @title Admin
*/
export default function App(
_props: unknown,
{ resolvables }: Props,
): App<Manifest, State> {
return { manifest, state: { storage: new FsBlockStorage() } };
return { manifest, state: { storage: new FsBlockStorage() }, resolvables };
}

export type AppContext = AC<ReturnType<typeof App>>;
2 changes: 1 addition & 1 deletion vtex/utils/batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export const batch = <T>(array: T[], size: number): T[][] => {
}

return batched;
};
};

0 comments on commit f070210

Please sign in to comment.