Comments (5)
Excellent feedback @telekid,
I think you're right that we should use a better name than middleware for the reason you state. The key idea is that we might want to transform the request before we bind request parameters to the function argument. We only want to do that when the function is being updated, not on the initial render. That's why its different from regular ring middleware. For the case where you want to transform the response object that should be handled by regular ring middleware.
For the case when you want to update e.g. headers simply use the req
middleware (name soon to be changed) as it receives the entire request object. I think prebind
might be a better name than middleware, do you agree?
from simpleui.
The key idea is that we might want to transform the request before we bind request parameters to the function argument
Makes sense.
We only want to do that when the function is being updated, not on the initial render.
Makes sense, though (I think?) I can imagine a different implementation that conditionally applies a traditional ring middleware within the standard ring middleware chain (but included via your current req
metadata strategy) when the component is serving as an endpoint root, but not when it is participating as a child component of a different render.
For the case when you want to update e.g. headers simply use the req middleware (name soon to be changed) as it receives the entire request object
In my case I'm interested in updating response headers, not request headers, so this won't quite do. I am still having trouble imaging how I might modify response headers as part of the same request that is returning an HTML fragment as part of a ctmx component re-render. Where would I put that traditional middleware? Should I modify the routes returned by ctmx's make-routes
function, manually appending middleware to the route that corresponds to the component in question? My initial reaction is that doing so feels a bit cumbersome.
from simpleui.
I would suggest you have two options. Firstly you can always return a regular ring response map from component update. By default when you return html represented as hiccup it is rendered and put into a response map. If the component returns a map ctmx
assumes it's already a valid ring response.
You can also use regular ring middleware and check for the HX-Request=true
header. Details. This is not set on initial render. The limitation is that it doesn't know exactly which component it is going to.
I could modify the existing middleware
option to receive both request and response but I wonder if its easier to just return a map directly from the component. What do you think?
from simpleui.
Apologies for the slow response!
I could modify the existing middleware option to receive both request and response but I wonder if its easier to just return a map directly from the component. What do you think?
This makes sense. Not sure why this hadn't occurred to me the first time around. I'll give this a shot next time I'm working in that area of my codebase.
Thanks for your help!
from simpleui.
@telekid here's a PR to address the issue https://github.com/whamtet/ctmx/pull/28/files
from simpleui.
Related Issues (20)
- Document that parameters need to be keywordized HOT 7
- Use the safer hiccup2.core/html to prevent XSS HOT 1
- Would ctmx need to be updated to align with latest release of htmx HOT 4
- rt/mapped-index and forms.. how should it work? HOT 4
- Document that one should call `ctmx.render/walk-attrs` over their body hiccup
- rt/map-indexed makes it difficult to use params in the component signature HOT 1
- json-params docs out of date
- Routing broken since forward to backwards slash change HOT 1
- Latest ctmx version in luminus template. HOT 2
- How to handle sibling components? HOT 3
- Add documentation for dependency injection
- The demo references ctmx 1.4.9, but Maven only has up to 1.4.8 HOT 3
- hx-vals not working out of the box with the kit template HOT 1
- clojurescript included by default HOT 2
- Specifying the endpoint URL for components HOT 3
- Fix warnings for clojure 1.11 HOT 2
- Fix some clj-kondo linting warnings for defcomponent / provide clj-kondo config OOTB
- ctmx.info returns 403 HOT 1
- How to choose routes? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simpleui.