Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add product extensions loader #205

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed doccache.zst
Binary file not shown.
4 changes: 2 additions & 2 deletions import_map.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"imports": {
"deco-sites/std/": "./",
"$live/": "https://denopkg.com/deco-cx/live@1.25.6/",
"$live/": "https://denopkg.com/deco-cx/live@1.29.2/",
"partytown/": "https://deno.land/x/[email protected]/",
"$fresh/": "https://denopkg.com/deco-cx/[email protected].3/",
"$fresh/": "https://denopkg.com/deco-cx/[email protected].6/",
"preact": "https://esm.sh/[email protected]",
"preact/": "https://esm.sh/[email protected]/",
"preact-render-to-string": "https://esm.sh/*[email protected]",
Expand Down
15 changes: 11 additions & 4 deletions live.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ import * as $$$24 from "./loaders/nuvemShop/nuvemShopProductList.ts";
import * as $$$25 from "./loaders/nuvemShop/nuvemShopProductListingPage.ts";
import * as $$$26 from "./loaders/x/image.ts";
import * as $$$27 from "./loaders/x/redirectsFromCsv.ts";
import * as $$$28 from "./loaders/x/redirects.ts";
import * as $$$29 from "./loaders/x/font.ts";
import * as $$$28 from "./loaders/x/extension.ts";
import * as $$$29 from "./loaders/x/redirects.ts";
import * as $$$30 from "./loaders/x/font.ts";
import * as $$$31 from "./loaders/x/productExt.ts";
import * as $$$32 from "./loaders/x/productDetailsExt.ts";
import * as $$$$0 from "./routes/404.tsx";
import * as $$$$1 from "./routes/styles.css.ts";
import * as $$$$2 from "./routes/_app.tsx";
Expand Down Expand Up @@ -214,9 +217,12 @@ const manifest = {
"deco-sites/std/loaders/vtex/proxy.ts": $$$11,
"deco-sites/std/loaders/vtex/user.ts": $$$17,
"deco-sites/std/loaders/vtex/wishlist.ts": $$$9,
"deco-sites/std/loaders/x/font.ts": $$$29,
"deco-sites/std/loaders/x/extension.ts": $$$28,
"deco-sites/std/loaders/x/font.ts": $$$30,
"deco-sites/std/loaders/x/image.ts": $$$26,
"deco-sites/std/loaders/x/redirects.ts": $$$28,
"deco-sites/std/loaders/x/productDetailsExt.ts": $$$32,
"deco-sites/std/loaders/x/productExt.ts": $$$31,
"deco-sites/std/loaders/x/redirects.ts": $$$29,
"deco-sites/std/loaders/x/redirectsFromCsv.ts": $$$27,
},
"routes": {
Expand Down Expand Up @@ -281,6 +287,7 @@ const manifest = {
"deco-sites/std/actions/vtex/wishlist/addItem.ts": $$$$$$$$$$$15,
"deco-sites/std/actions/vtex/wishlist/removeItem.ts": $$$$$$$$$$$14,
},
"name": "deco-sites/std",
"pages": {
"$live/pages/LivePage.tsx": i1$$$0,
},
Expand Down
25 changes: 25 additions & 0 deletions loaders/x/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { PromiseOrValue } from "$live/engine/core/utils.ts";

/**
* @title The type extension.
*/
export type ExtensionOf<T> = (value: T) => PromiseOrValue<void>;

export interface Props<T> {
/**
* @title Data
* @description Here comes your products or anything that can be extensible.
*/
data: T;
/**
* @title The data Extensions
*/
extensions: ExtensionOf<T>[];
}

export default async function Extended<T>(
{ data, extensions }: Props<T>,
): Promise<T> {
await Promise.all(extensions.map((ext) => ext(data)));
return data;
}
11 changes: 11 additions & 0 deletions loaders/x/productDetailsExt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ProductDetailsPage } from "../../commerce/types.ts";
import { default as extend, Props } from "./extension.ts";

/**
* @title Extend your products
*/
export default function ProductExt(
props: Props<ProductDetailsPage | null>,
): Promise<ProductDetailsPage | null> {
return extend(props);
}
11 changes: 11 additions & 0 deletions loaders/x/productExt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Product } from "deco-sites/std/commerce/types.ts";
import { default as extend, Props } from "./extension.ts";

/**
* @title Extend your products
*/
export default function ProductExt(
props: Props<Product[] | null>,
): Promise<Product[] | null> {
return extend(props);
}