-
-
Couldn't load subscription status.
- Fork 1k
Mount API proposal
Will McGugan edited this page Nov 1, 2022
·
1 revision
# Mount at start
self.mount(Foo())
self.mount(Foo(), before=0)
# Mount before first Foo
self.mount(Foo(), before="Foo")
# Equivalent to...
self.mount(Foo(), before=self.query_one("Foo"))
# Mount multiple widgets
self.mount(Foo(), Bar(), Baz())
# Mount at end
self.mount(Foo())
self.mount(Foo(), after=-1)
# Add widget after another widget
self.mount(Foo(), after="#bar")There will be other options once we implement :first and :last psuedo-selectors
# Mount before first Foo
self.mount(Foo(), before="Foo:first")
# Mount after last foo
self.mount(Foo(), after="Foo:last")Thinking about selectors. Calling self.query would return grandchildren. It would be reasonable to expect that to do the same in mount. I think that a selector, i.e. self.mount(Foo(), before="Foo") should effectively do a query_one and mount before that widget, which may not be an immediate child.
Here's the equivalent JS API:
https://developer.mozilla.org/en-US/docs/Web/API/Node/appendChild
There's a ton of methods which do much the same as the proposed mount.