Hey all,
I’ve stumbled on to a modification of the “one click nav handler” from the Docs that seems to work better for me than the provided example. I want to put it up here so anyone can tell me if there’s a good reason not to do it this way.
In the docs, each link clicked has an associated tag with an instance of the page it should display, like so:
# set each Link's `tag.form_to_open` attribute to an instance of the Form you want to open
self.home_link.tag.form_to_open = Home()
self.about_link.tag.form_to_open = About()
self.contact_link.tag.form_to_open = Contact()
That tag is accessed as:
form_to_open = event_args['sender'].tag.form_to_open
This created some issues for me, though, as I was managing my data on the page level (ie, the Product List page should retrieve a list of products). The big issue was that the above setup causes each page to retrieve the data when the app is first loaded. This meant that:
A) All my pages were making their trips to the database at once
B) The page’s data reflected the data as it was when the app loaded, not when the link was clicked (what if it was edited on another page since the app was loaded?)
I discovered that not instantiating the page until the link is clicked solves these problems. Instead of storing the tag as above, I would do so without the parentheses at the end (without instantiating) like so:
self.home_link.tag.form_to_open = Home
self.about_link.tag.form_to_open = About
self.contact_link.tag.form_to_open = Contact
Then when we grab it from the tag:
form_to_open = event_args['sender'].tag.form_to_open()
This will cause a page to only load its data when its link is clicked, not pre-load the data. If you ever need to refresh your data on a page, like after editing something in the table, you simply run its init again.
While page loading times are ever so slightly higher because of the server call when the page is loaded, it saves the complexity of having to manage all my client side data in a single spot.
Am I missing a reason why this might be a bad idea? Its not even mentioned as a possibility in the docs (as an alternative to pre-loading all your client-side data up front).