Prefactor some parts to reduce size of other PR#109
Conversation
davepeck
left a comment
There was a problem hiding this comment.
This seems like a good pre-factor. But I'm a little unclear on where we're heading with component invocation?
|
|
||
| with pytest.raises(TypeError): | ||
| _ = html(t"<p>The sum is {add}.</p>") | ||
| _ = html(t"<p>The sum is {add:callback}.</p>") |
There was a problem hiding this comment.
Interesting. How should I think about :callback?
Our dataclass-style components historically depend on tdom always calling callables if it finds them in content position. Has this also changed?
There was a problem hiding this comment.
Maybe: "call back to this function to get the effective value to plug into this interpolation whenever you end up processing this template". It is general purpose but by making it opt-in we don't have to check every single interpolation value to see if it is a callable or not.
Since this is a mixed bag of changes that were more easily extractable it might seem a little out of place but the other PR removes processing callables automatically and you HAVE to opt-in except for components which are their own flow.
Instead of going back out to start all over again ...
Line 505 in f210a36
... if the component callable is a factory then it is just immediately called a second time to get the Template.
So instead of running everything through the same node_from_value function we have more dedicated flows that resolve values with more context.
There was a problem hiding this comment.
if the component callable is a factory then it is just immediately called a second time to get the Template
Ah, that makes sense. That's a better approach. Basically, a "component" can return a Template or a (zero-arg) callable. Fine.
|
@ianjosephwilson This feels mergable. Agreed? |
|
Yes, should be just rearranging things and adding things, I don't think anything really changes. |
|
Thank you thank you! |
htmlspec.pyprotocols.pysentinel.pyTemplateRefadditionsTemplate.__iter__does.Templateobject in between theTemplateRefstringsbased on thei_indexes."callback"format_spec triggers new formatterTemplatebeing called automatically.