This repository has been archived by the owner on Aug 10, 2024. It is now read-only.
V2 and Props #68
pauleveritt
started this conversation in
General
Replies: 2 comments
-
Note: Added an important "last point" at the end. |
Beta Was this translation helpful? Give feedback.
0 replies
-
I think from antidote import const, inject, lazy, world
class Conf:
PUNCTUATION = const('!')
@lazy
def Greeting(name: str, punctuation: str = inject[Conf.PUNCTUATION]) -> str:
return f"<p>Hello {name}{punctuation}</p>"
assert world[Greeting(name='Antidote')] == "<p>Hello Antidote!</p>"
assert world[Greeting(name='someone', punctuation='???')] == "<p>Hello someone???</p>" |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm back in "book writing" mode. I'd like to explore "props" from the previous, so I can bring my antidom repo into the book.
tl;dr Where do "props" get into injection, how are they used during instantiation?
Imagine I have "template":
<p><{Greeting} name="Antidote" /></p>
. This results in:<p>Hello Antidote!</p>
Hello
comes from a component local variable,Antidote
from a passed-in "prop", and!
is injected.Maybe I have:
Maybe I have class-based:
The second version offers the possibility to pass the props into the call. On one hand, that's unattractive, as results will never get cached. OTOH, the instance of these props would have to be in
state
somewhere. Which might be a good answer.Or perhaps I need to write a provider. Maybe I need to anyway, to customize the
.update
of injection?Last point: a prop should be able to override an injected value. In the above, I should be able to pass in my own punctuation for a specific usage:
<p><{Greeting} name="Antidote" punctuation="??" /></p>
Beta Was this translation helpful? Give feedback.
All reactions