Skip to content
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

Data widget example. #230

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

hydra
Copy link
Contributor

@hydra hydra commented Dec 10, 2024

Commit 5119f5f added data() but this example shows how it's not obvious or possible to access the data once the widget has been created.

Looking for suggestions on how to access the data from the widget tree once the widget has been created.

@hydra hydra changed the title Data example. Data widget example. Dec 10, 2024
@ecton
Copy link
Member

ecton commented Dec 19, 2024

This is sort of why I said that Cushy is the "View" layer if you were to think of a MVC type architecture. It isn't really meant to be the data storage layer -- it's meant to be the interactive representation of your model.

That being said, a WidgetInstance can be cloned cheaply and can be locked and downcasted back to the underlying widget type. So, while you are consuming the widget while building the Stack, you could make_widget() to get a WidgetInstance, store a clone, and then access it that way. However, at the moment you're storing a clone of the data widget -- why would you not just clone the original data and store that instead? That's what feels weird about trying to store data in Cushy -- to create the Data widget, you must provide the data to the widget. And to access the data stored in the hierarchy, you must somehow gain a reference to the correct widget. The same amount of work it takes to store the widget reference could easily store a copy of the data in question instead.

To me the Data widget is exactly what it is described as: a way to ensure some piece of data isn't dropped before widgets that rely on that data not being dropped are dropped themselves. That's what Cushy is using it for internally, and the main reason it exists. It really shouldn't be used by most users, and probably is only useful for exactly how the progress bar is using it: to use widget composition instead of creating a new Widget type and allowing for data to be stored in the hierarchy and kept alive until the composed widget is dropped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants