From fb838ba9100bca6c8e1a6a3a6a3b5c0abd4dd864 Mon Sep 17 00:00:00 2001 From: Jonas Galvez Date: Mon, 19 Feb 2024 20:37:40 -0300 Subject: [PATCH] feat(htmx): ability to predecorate req and reply --- packages/fastify-htmx/index.js | 12 ++++++++++++ packages/fastify-htmx/package.json | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/fastify-htmx/index.js b/packages/fastify-htmx/index.js index 247a62d0..c2849786 100644 --- a/packages/fastify-htmx/index.js +++ b/packages/fastify-htmx/index.js @@ -20,6 +20,18 @@ async function prepareClient(clientModule, scope, config) { } const { routes } = clientModule for (const route of routes) { + // Predecorate Request and Reply objects + if (route.decorateRequest) { + for (const prop of route.decorateRequest) { + !scope.hasRequestDecorator(prop) && scope.decorateRequest(prop, null) + } + } + if (route.decorateReply) { + for (const prop of route.decorateReply) { + !scope.hasReplyDecorator(prop) && scope.decorateReply(prop, null) + } + } + // Pregenerate prefetching elements const { css, svg, js } = await findClientImports( config.vite.root, route.modulePath, diff --git a/packages/fastify-htmx/package.json b/packages/fastify-htmx/package.json index 3ac71cde..e0814ac9 100644 --- a/packages/fastify-htmx/package.json +++ b/packages/fastify-htmx/package.json @@ -6,7 +6,7 @@ "main": "index.js", "name": "@fastify/htmx", "description": "The official @fastify/vite renderer for HTMX", - "version": "0.1.0", + "version": "0.2.0", "files": [ "virtual/layouts/default.jsx", "virtual/client.js",