Skip to main content

The SpaStateManager class

Deserted Chateau's SPA is implemented via this class, and can be enabled or disabled by users via their navigation settings.

Registering page render params

Each JavaScript class that runs for a given page (e.g. DisplayArtwork.js, UserProfile.js), on page load, registers its parameters with SpaStateManager in order for the state manager to know what it needs to render that page if required by a user going back/forward. Example:

// From BrowseArt.js

$(function () {
    SpaStateManager.registerPageRenderParams({
        pageType: "/browse/art",
        pageInitFunc: BrowseArt.initialise,
    });
    if (!SpaStateManager.pageIsLoadedViaAjax("/browse/art")) {
        dcLogger.debug(color() + "Initialising Browse Art");
        BrowseArt.initialise();
    }
});
Page types and page identifiers

Pages all have a unique page type, corresponding to their backend URL before any Apache redirects.

Page identifiers are used to distinguish different pages of the same page type; for example, a user might browse multiple user profiles, which each will be rendered as their own separate subpage.

Page types and identifiers are stored in the subpage's containing div element, using the dc-page-type and dc-page-identifier attributes.