-
-
Notifications
You must be signed in to change notification settings - Fork 102
Allow SGML attributes to accept objects which respond to to_h #925
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
base: main
Are you sure you want to change the base?
Conversation
|
Should add Im not sure what the exact implications are of allowing anytihing that responds to |
|
This sounds reasonable to me. I think you could get same effect by putting |
|
Oh, I think the reason we’ve avoided this so far is due to difficulties caching. It would force us to do an un-cacheable step to prepare the cache key. |
|
Ah right. Yes currently I do |
|
For us to allow regular to_h-able objects, we would need to either iterate over each key of the attributes looking for to_h-ables and converting them in advance of the cache check (slow), or trust that your object has implemented hashing correctly and is safe to store in the cache for a long time (potentially quite dangerous). |
|
Perhaps we trust your object’s |
|
Just chipping in to say that I'd also find this useful. I have builder objects that can then pass their properties as DOM element attributes to Phlex, such as Re. the small performance hit. With the new Phlex compiler: 1). Would the perf gains from the compiler offset this perf. hit sufficiently to make it less important? |
|
I will take another look at this soon as I would like to support it. I don’t think there’s any way for the compiler to improve performance here as the compiler will fall back to dynamic attribute generation anyway if the attributes contain non-literals. It will only be able to compile attributes that are entirely literals. It’s possible we could split the literal and non literal parts, but that’s tricky because I believe the order of HTML attributes is significant. Performance is fine if we can cache the input. The thing I’m worried about is if we’re given an object that does not correctly implement We could theoretically implement it in a way that it calls |
|
Could there be an optional module that one can include in their custom data classes that implements a "Phlex cache safe" set of methods? Eg Not sure if this makes sense at all, as don't know if the hash generation can be generalised like this |
I think it would be nice to be able to use things like instances of
Datafor your tag attributes, egdiv(data: my_data_object)
Currently this raises:
Here is one possible solution, simply check if value responds to
#to_h