-
Notifications
You must be signed in to change notification settings - Fork 0
Handling multiple apps
Anil Maharjan edited this page Dec 16, 2020
·
5 revisions
You can have any number of applications on a page. Instanciate a new Comfey whenever you need.
- Multiple app can use duplicate state names
- they will be scoped within each app
- You will have to scope your javascript as well
- Just avoid declaring getters and setters globally
Example
// scoped code blocks can use same getters / setters, etc names if desired.
// name uniquely if needs to be in the same scope
// PrimaryMenu app will take care of primary menu
(() => {
const primaryMenu = new Comfey(document.getElementById('primary-menu'), COMFEY_DEBUG);
const [, setActive] = primaryMenu.useState('stateActive', false);
setInterval(() => {
setActive(Math.random() > 0.5);
}, 1000);
})();
// SecondaryMenu app will take care of secondary menu
// Note the closure.
(() => {
const secondaryMenu = new Comfey(document.getElementById('secondary-menu'), COMFEY_DEBUG);
const [, setActive] = secondaryMenu.useState('stateActive', false);
setInterval(() => {
setActive(Math.random() > 0.5);
}, 1000);
})();
Read more about ← Comfey state Watchers | Comfey Templating →