Closed benpate closed 1 year ago
+1 on this. Would very much love to quickly drop in some lightweight preferences mgmt and it couldn't be easier to read than above ⬆️
I like it!
I looked at this a little bit tonight. It seems like the changes here should go into the runtime.resolveSymbol()
and runtime.setSymbol()
functions.
However, if we do that, it might be hard to include features like ... expiring tomorrow
but perhaps that could be included/overridden in a configuration function named something like htmx.config.setCookie()
.
@1cg, do you agree? If so, I think I can make this update. Or, give me your guidance if you have other thoughts, and I'll happily adjust this plan.
I think this would be a new expression type, with the start cookie
and then a custom syntax after that for declaring expiration, etc.
The expression itself would return the value of the cookie, and then you'd need to update set
and put
to handle setting values in the cookies (ideally by deferring to the cookie expression itself)
I'm rubbish at JS so I can't offer much here but excitement and thanks :) (and if you need some testing, I'm trying to launch a couple pages this weekend and could include a build; the basic feature is just remembering some filter preferences (probably an array or two) so if it failed gracefully it's no biggie.
@1cg -- I think I follow. I was heading down the road of making it a namespace. I'll aim at expressions and see where I get. Not totally sure I follow what the changes would be to the set
statement, but let me knock it around for a bit first before I cry for help.
@rtgoodwin - cool, thanks. I'm not sure when I'll have something testable, but I'll reference this issue in the PR when I have something worth sharing. More eyes are always better!
Some cookie support in hyperscript would be great as it is one of the only reasons why I sometimes use Alpine.js + js-cookie instead of HTMX + hyperscript.
Hey @1cg do you think this is something that will eventually make it into Hyperscript?
how do people feel about this?
@1cg I think that's perfect.
Can we implement a way to add/remove cookies in hyperscript? This is similar to #127, but for stylesheets:
If we add expression
cookie
(similar totag
,input
, orbutton
from #121) that would identify a named cookie then we could do something like this:Again, this is a hot take on giving hyperscript the ability to manage stylesheets dynamically, and I'm happy to keep looking for better options.