Understanding how BrowserForestManager works
#675
cruxcode
started this conversation in
Guides: Atri Framework Reference
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
A web app created using the Atri framework is a single-page app (SPA) that contains many routes. We call each of these routes a page (sorry for the confusion here).
Only one page is visible on the canvas at a time. Let's call this page the
current pagein the rest of the discussion. We can change thecurrent pageby using the Page manager in the top left corner of the editor. Whenever we set a different page as the newcurrent page, the rest of the code in our editor needs to be informed about this change. One way to achieve this was using thePub-Submodel where the code that depends on thecurrent pagewill unsubscribe to changes to the oldcurrent pageand subscribe to changes to the newcurrent page. This approach ofPub-Subis not a clean code pattern and it would be better if this subscribing-unsubscribing can be handled within some clean interface.This is where the
BrowserForestManagerfrom the@atrilabs/corepackage shines. The rest of the discussion assumes that the reader is already familiar with the concept ofevents&forestin our codebase. If not please read this discussion first before moving ahead in this discussion. The code pattern to subscribe to changes to thecurrent pagewould be as shown below:If you are writing a custom react hook or a React component, the usual code pattern that you would like to use is shown below:
Each forest has many trees, for example, there is a tree for storing CSS of components, a tree to store components, a tree to store custom properties, etc. To access a particular tree of the
current page, you use theidof the tree along withBrowserForestManager.currentForestas shown below:If you are writing a custom react hook or a React component, the usual code pattern that you would like to use is shown below:
Beta Was this translation helpful? Give feedback.
All reactions