some-airline-73512
03/16/2023, 11:39 AMsome-airline-73512
03/16/2023, 11:42 AMjs
// in controller:
const context: Context = {/*...*/}
renderTyped['template.njk'](res, context)
type Context = {
field: string,
}
// then in a separate file: html-contract.ts:
export const renderTyped = {
'template.njk': (res: Response<any>, context: ContextContract) => {
res.render('template.njk', context)
},
}
type ContextContract = {
field: string, // if you change field Context, then the compiler will force you to go here and change field in ContextContract
}
some-airline-73512
03/16/2023, 11:45 AMsome-airline-73512
03/16/2023, 11:47 AMsome-airline-73512
03/16/2023, 11:51 AMtemplate.njk()
in stack-trace as a method name. I immediately understand what template took long time to render.
Compared to generic render()
in stacktrace, it's very satisfying to work with.bulky-pillow-43958
03/16/2023, 3:49 PMlimited-teacher-83117
03/16/2023, 5:28 PMjs
async function copyLink() {
const domain = window.location.origin
navigator.clipboard.writeText(`${domain}/my-link-here`)
}
And you can just onclick="copyLink()"
to the element of your choosinglimited-teacher-83117
03/16/2023, 5:33 PMhx-on
proposal, since I'm the one who made it:
> Isn’t it basically x-on from alpine.js?
I know a lot of people like using alpinejs here, but "another library has a similar feature" is a sign that the feature is useful, and might benefit from being included in this library
> imo this is exactly what hyperscript is for
hyperscript is for specifying what happens after a browser interaction (an event, a click, etc). The hx-on
proposal adds an additional when that lets people trigger the effects described by hyperscript within the event-processing framework set up automatically by HTMX. hyperscript can do it with "on", but you shouldn't have to pull in a whole additional library to take advantage of something HTMX is already doing for you
I'm not really wedded to hx-on-*
, because while that might be useful and idiomatic, it's a big surface area that deserves some consideration. I really want to be able to call out to some action based on an HTMX trigger, i.e. hx-on-trigger
. You can already do this with events, but you cannot specify them inline, which means that you are responsible for setting and removing the listener (and not setting a new listener each time another element is swapped in). The hx-
attributes are basically just inline event listeners that HTMX takes care of adding and cleaning up for you, so it would be very handy to extend that paradigm to HTMX's existing client-side triggers (whether you want to use hyperscript, alpinejs, or just plain JS without additional libraries)shy-knife-59740
03/16/2023, 8:18 PMadventurous-ocean-93733
03/16/2023, 9:19 PMabundant-dog-96915
03/17/2023, 1:31 AMabundant-dog-96915
03/17/2023, 4:42 AMabundant-dog-96915
03/17/2023, 4:42 AMlate-king-98305
03/17/2023, 1:19 PMagreeable-midnight-69265
03/17/2023, 2:23 PMmysterious-toddler-20573
03/17/2023, 2:30 PMtall-dinner-62086
03/17/2023, 2:32 PMorange-umbrella-16693
03/17/2023, 2:40 PMripe-action-67367
03/17/2023, 2:41 PMripe-action-67367
03/17/2023, 2:42 PMarr[0] = value
or object.prop = value
, or called a function that mutates the object inplace, the compiler does not actually know that the values was updatedripe-action-67367
03/17/2023, 2:42 PMripe-action-67367
03/17/2023, 2:42 PMripe-action-67367
03/17/2023, 2:43 PMarr = arr
ripe-action-67367
03/17/2023, 2:43 PMorange-umbrella-16693
03/17/2023, 3:15 PMorange-umbrella-16693
03/17/2023, 3:15 PMfreezing-waitress-26396
03/17/2023, 3:17 PMfreezing-waitress-26396
03/17/2023, 3:17 PMarr = arr
echoing-lion-55988
03/17/2023, 3:21 PM