-
-
Notifications
You must be signed in to change notification settings - Fork 580
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
using hierarchical path names to identify JS dependencies #1134
Conversation
…com:zauberzeug/nicegui into path_improvements # Conflicts: # nicegui/elements/joystick.py
I've spent quite some time with the dependency registration (again). Unfortunately there are still problems. E.g. the first AG Grid demo doesn't update the age when clicking "Update" for the first time. Additional clicks do work though. Maybe that's the main reason why many tests are red. Or maybe there are more problems. I don't know at the moment. Apart from that I'm still not very pleased with the API for registering dependencies. As soon as we leave the NiceGUI library and register a custom component in one of our examples, the I just spiked with passing arguments when subclassing a UI element: class Image(SourceElement, component='image.js'):
... My plan was that the directory of the subclassing class (Image in this case) is automatically the base path for the dependency. The subclassing method might look something like this: def __init_subclass__(cls, *,
component: Union[str, Path, None] = None,
libraries: List[Union[str, Path]] = [],
exposed_libraries: List[Union[str, Path]] = []) -> None:
super().__init_subclass__()
base_path = Path(inspect.getfile(cls)).parent
cls.components = [register_vue_component(Path(component), base_path)] if component else []
cls.libraries = [register_library(Path(library), base_path) for library in libraries]
[register_library(Path(library), base_path, exposed=True) for library in exposed_libraries] When instantiating the subclass, components and libraries are already assigned. Furthermore, the But what to do with Long story short: I've got the feeling that we're on the brink of finding a really nice API. I'd like to think about it once again on Monday. Since it involves breaking API changes anyway, we should wait with the 1.3 release until this is resolved. |
Yes, I think the libraries for
Furthermore we could support globbing: class Mermaid(ContentElement,
component='mermaid.js',
exposed_libraries=['lib/mermaid/mermaid.esm.min.mjs'],
extra_libraries=['lib/mermaid/*.js']):
... |
There's still one problem to be tackled: def go():
grid = ui.aggrid({'columnDefs': [{'field': 'name'}], 'rowData': [{'name': 'Alice'}]})
grid.call_api_method('selectAll')
ui.button('Go', on_click=go) When pressing the button for the first time, the frontend loads the AG Grid dependency asynchronously before actually rendering the element. In the meantime the API call is ineffective and no rows are selected. The second click works though. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I think we're finally ready to merge. Today I struggled a bit with another Mermaid bug (not caused by this PR but already present in the 1.3 branch), but I could fix it with a queue in mermaid.js handling async processes one at a time.
Now the dependency API is really nice, supports globbing and works with hashed paths behind the scenes.
ToDos
Path('foo/bar')
on Windowselement.components
intoelement.component