Hi All,
I am currently creating a multipage application using canjs, and have a question regarding the best way to structure things.
I am using requireJS to manager dependencies in the js (I wasn't familiar with steal when I first started, but if someone wants to convince me to switch I am open to change).
I also have a system that auto hooks up can controls based on data-attributes on certain dom elements, for instance if an element has the attribute data-module="core/controls/exampleControl", to setup the controls I just scan the page for these elements, require that control and initialize it. In order to handle any global event hookups or routing I have an Application control, which is added to the body element.
However, when it comes to handling the client side state of the app I am not convinced of a good solution. For example, when I log a player into the app I would like to keep track of some player details and preferences so that views can react accordingly. Some of my thoughts so far:
1.) Have a Player model (along with others for the other parts of the state to be managed), although there will only be a single instance of it and will probably be updated directly when the login call completes, rather than calling findOne.
2.) Have a global Observe for the app state for which various objects are added to. So when a player logs in the player object is added to this observe - Nice to have everything globally accessible, but will be the only object that is accessed from the global scope so feels a little wrong
3.) Have a single observe object that can be pulled into other parts of the app as a dependency, so it can be globally available but never accessed from the global scope.
4.) Have the main AppController contain an observe/collections of observables to store the state
So I am really intrigued, how have others managed this structural problem in multipage apps. I want to have a lot of freedom in my can views to live bind to anything in the application state, and would ideally like to avoid chucking something on the window.
Many thanks,
Adam