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

Cleanup examples #341

Closed
wants to merge 2 commits into from
Closed
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
45 changes: 0 additions & 45 deletions JS/edgechains/examples/Test01/esbuild.build.js

This file was deleted.

4 changes: 4 additions & 0 deletions JS/edgechains/examples/Test01/htmljs.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export declare const view: (viewToRender: any) => (c: any) => Promise<any>;
export declare const rootLayout: (layoutToApply: any) => (c: any, next: any) => Promise<void>;
export declare const layout: (layoutToApply: any) => (c: any, next: any) => Promise<void>;
export declare const Link: any;
52 changes: 52 additions & 0 deletions JS/edgechains/examples/Test01/htmljs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { html } from "hono/html";
// These functions form the basis of the html.js framework and will be moved to a separate lib
export const view = (viewToRender) => {
return async (c) => {
const newBody = await viewToRender({ context: c });
return c.html(newBody);
};
};
export const rootLayout = (layoutToApply) => {
return async (c, next) => {
await next();
if (c.req.header("HX-Request") !== "true") {
// Req is a normal request, so we render the whole page which means adding the root layout
const curBody = await c.res.text();
c.res = undefined; // To overwrite res, set it to undefined before setting new value https://github.com/honojs/hono/pull/970 released in https://github.com/honojs/hono/releases/tag/v3.1.0
const newBody = await layoutToApply({ context: c, children: html(curBody) });
c.res = c.html(newBody);
}
// Else do nothing and let the original response be sent
};
};
export const layout = (layoutToApply) => {
return async (c, next) => {
await next();
if ((c.req.header("HX-Request") === "true" &&
(c.req.header("HX-Boosted") === "true" || !c.req.header("HX-Target"))) ||
c.req.header("HX-Request") !== "true") {
// Req is regular req or boosted link, so we apply layouts
const curBody = await c.res.text();
c.res = undefined; // To overwrite res, set it to undefined before setting new value https://github.com/honojs/hono/pull/970 released in https://github.com/honojs/hono/releases/tag/v3.1.0
const newBody = await layoutToApply({ context: c, children: html(curBody) });
c.res = c.html(newBody);
}
// Else do nothing and let the original response be sent, which will be a partial update applied to the page with hx-target
};
};
export const Link = ({ to, "hx-target": hxTarget, class: className, children }) => {
if (hxTarget) {
return html `<a
href="${to}"
class="${className}"
hx-get="${to}"
hx-target="${hxTarget}"
hx-push-url="true"
hx-swap="morph"
>${children}</a
>`;
}
else {
return html `<a href="${to}" class="${className}" hx-boost="true">${children}</a>`;
}
};
14 changes: 10 additions & 4 deletions JS/edgechains/examples/Test01/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@
"version": "1.0.0",
"description": "",
"main": "dist/index.js",
"type": "module",
"scripts": {
"build": "rm -rf dist && node esbuild.build.js",
"start": "node dist/index.js",
"start": "node --experimental-wasm-modules ./src/index.js",
"lint": "eslint --ignore-path .eslintignore --ext .js,.ts",
"format": "prettier --ignore-path .gitignore --write \"**/*.+(js|ts|json)\"",
"test": "npx jest"
},
"jest": {
"setupFiles": [
"<rootDir>/setupTests.js"
]
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@arakoodev/jsonnet": "^0.1.2",
"@hono/node-server": "^1.2.0",
"@types/dotenv": "^8.2.0",
"hono": "^3.9.2",
Expand All @@ -23,7 +30,7 @@
"typescript": "^5.3.2"
},
"devDependencies": {
"@hanazuki/node-jsonnet": "^2.1.0",
"@arakoodev/edgechains.js": "0.1.22",
"@types/jest": "^29.5.8",
"@types/node": "^20.9.4",
"@typescript-eslint/eslint-plugin": "^6.11.0",
Expand All @@ -40,10 +47,9 @@
"jest": "^29.7.0",
"prettier": "^3.1.0",
"react": "^18.2.0",
"@arakoodev/edgechains.js": "0.1.22",
"ts-jest": "^29.1.1",
"tsx": "^3.12.2",
"typeorm": "^0.3.17",
"typescript": "^5.0.2"
}
}
}
1 change: 1 addition & 0 deletions JS/edgechains/examples/Test01/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "dotenv/config";
12 changes: 12 additions & 0 deletions JS/edgechains/examples/Test01/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import "dotenv/config";
import { serve } from "@hono/node-server";
import { Hono } from "hono";
import { HydeSearchRouter } from "./routes/hydeSearch.route.js";
import { view } from "../htmljs.js";
import ExampleLayout from "./layouts/ExampleLayout.js";
const app = new Hono();
app.route("/", HydeSearchRouter);
app.get("/", view(ExampleLayout));
serve(app, () => {
console.log("server running on port 3000");
});
3 changes: 3 additions & 0 deletions JS/edgechains/examples/Test01/src/layouts/ExampleLayout.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { FC } from "hono/jsx";
declare const ExampleLayout: FC;
export default ExampleLayout;
Loading
Loading