Transformer Proof-of-Concept#101
Conversation
…s in structure template interpolations.
…marker for this during parsing instead of having this weird component return API.
|
@ianjosephwilson That certainly would work for test-writing but it would eliminate other uses of But I'm also interested in interoperability. For example, I have a decorator that lets an |
b7bfe25 to
6455889
Compare
|
Wow, lots to think through here. Thank you. In lieu of an organized response, here's a grab bag of thoughts:
Ian, curious how you're feeling about the direction overall. |
|
@ianjosephwilson and I had a long chat this afternoon. I really enjoyed it and I now understand much better his thinking and his direction.
2a. First fly in the ointment: this means the 2b. It means 2c. Some of my needs require component information (e.g. paths relative to component disk location.) It so happens this relates to tracing -- the need for good error messages.
|
@pauleveritt Whew! Thanks for meeting. It is going to take a while for my brain to digest all that information. It has given me a few ideas though already.
I really like the approach-ability and simplicity of the Template IN Template OUT concept. I realized we can keep using def Comp(children: Template):
return t'<div>{children}</div>'
node = Element('span', children=[Text('1')])
# Behold! A Template!
children_template = t'{node:safe}'
# type system says Template IN Template OUT... OK!
comp_template: Template = Comp(children=children_template)This could maybe provide that escape hatch to go to Nodes early. I have to think more about that.
Some of these are supported and maybe I still didn't explain the difficulties with the hybrid static-vs-dynamic -- static: "we know" and dynamic: "we can't know until we render" very well. We touched on it but I need some better examples and maybe a "visualization" we could see.
I'm not 100% sure about this but I guess if its to walk the tree then yeah it won't work well. I think I need to push these examples along a bit and we could start experimenting with this.
This did panic me a bit because it seems like it could be a real show stopper issue but I think there is a caveat. TDOM should be able to retain some sort of information when it invokes a component and gets a template back. I'm not sure exactly how its going to track that and I have some "questionable" strategies to try but it seems like it should be possible to say this component made this template. The intention being to either tack on something we need later or to provide debugging information when a nested component in that template fails. I need to research this and probably look at some other systems.
We still have the TNodes which provide the DSL information but the transformed template is more limited. I will try to come up with some sort of visual / explanation to improve clarity here. I have a hard time explaining it as well as understanding it myself. |
I agree things are a bit muddled here. I wanted to keep the performance in view while trying to get the feature-set under control and really iron out what is happening. In a way similar to the attribute resolution. I think doing them both at the same time here actually helped with that. I am going to try to untangle that a bit so we can look at the core functionality and then decide if this transformation is still helping.
This is my feeling too and maybe some of the more "middleware" use-cases @pauleveritt wanted/needs could be resolve in other ways or with some more advanced functionality. The most common case would be to have
I did see that but it seems react has moved away from manipulating those children and more towards treating it as a "opaque" slot. I think that would be our common case but you could do all sorts of weird stuff as long as the end result is another
As mentioned before some of that "cleanup" is bundled into this and needs to be called out probably in another PR of some sort. I tried to really constrain what could be in there.
I agree but I wanted to be sure that the system still would be compatible with this alternative design. Most notably this situation: >>> def Inner(children):
... print ('Inner')
... return t'<span>{children}</span>'
...
>>> def Outer(children):
... print ('Outer')
... return t'<div>{children}</div>'
...
>>> res = html(t'<body><{Outer}><{Inner}>{"CONTENT"}</{Inner}></{Outer}></body>')
Inner
Outer
>>> res = render_service_factory().render_template(t'<body><{Outer}><{Inner}>{"CONTENT"}</{Inner}></{Outer}></body>')
Outer
Inner
I've been pretty convinced we should use
|
Proof of concept for discussion, needs tests and more refactoring.
TNodetree into a newTemplateafter parsing to determine the structure.Templatedirectly tostrwithoutNodeusing iterative solution.tdom's rendering of descendents by returning adict[str, object]in a 2-tupletdomto set context vars for descendent components to access by returning(Template, {'context_values': ((CTX_VAR, 'value-to-set'),)})kwargscan be provided to participating components (beyond justchildren).def Component(sys_context, children) -> TemplateSome of this we might be able to back-port into
tdom'sNoderenderer.