Options
All
  • Public
  • Public/Protected
  • All
Menu

ModelManager is main entry point of this module.

Example:

Boostrap: index.html

<head>
<meta property="cq:pagemodel_root_url" content="{PATH}.model.json"/>
</head>

Bootstrap: index.js

import { ModelManager } from '@adobe/aem-spa-page-model-manager';

ModelManager.initialize().then((model) => {
// Render the App content using the provided model
render(model);
});

// Loading a specific portion of model
ModelManager.getData("/content/site/page/jcr:content/path/to/component").then(...);

For asynchronous loading of root model/standalone item model

import { ModelManager } from '@adobe/aem-spa-page-model-manager';

ModelManager.initializeAsync();
...
// Render the App independent of the model
render();

For root model, custom event is fired on window with fetched model - cq-pagemodel-loaded

Hierarchy

  • ModelManager

Index

Constructors

Accessors

  • get rootPath(): string
  • Returns the path of the data model root.

    Returns string

    Page model root path.

Methods

  • _isRemoteApp(): boolean
  • Checks if the currently open app in aem editor is a remote app

    Returns boolean

    true if remote app

  • addListener(path: string, callback: ListenerFunction): void
  • Add the given callback as a listener for changes at the given path.

    Parameters

    • path: string

      Absolute path of the resource (e.g., "/content/mypage"). If not provided, the root page path is used.

    • callback: ListenerFunction

      Function to be executed listening to changes at given path.

    Returns void

  • Initializes the ModelManager using the given path to resolve a data model. If no path is provided, fallbacks are applied in the following order:

    • meta property: cq:pagemodel_root_url
    • current path of the page

    If page model does not contain information about current path it performs additional fetch.

    fires

    cq-pagemodel-loaded

    Type parameters

    Parameters

    Returns Promise<M>

  • Initializes the ModelManager asynchronously using the given path to resolve a data model. Ideal use case would be for remote apps which do not need the page model to be passed down from the root. For remote apps with no model path, an empty store is initialized and data is fetched on demand by components.

    Once the initial model is loaded and if the data model doesn't contain the path of the current pathname, the library attempts to fetch a fragment of model.

    Root model path is resolved in the following order of preference:

    • page path provided via config
    • meta property: cq:pagemodel_root_url
    • current path of the page for default SPA
    • if none, it defaults to empty string
    fires

    cq-pagemodel-loaded if root model path is available

    Parameters

    Returns void

  • removeListener(path: string, callback: ListenerFunction): void
  • Remove the callback listener from the given path path.

    Parameters

    • path: string

      Absolute path of the resource (e.g., "/content/mypage"). If not provided, the root page path is used.

    • callback: ListenerFunction

      Listener function to be removed.

    Returns void

Generated using TypeDoc