UNPKG

3.84 kBTypeScriptView Raw
1import { Model } from './Model';
2import { ModelClient } from './ModelClient';
3import { ModelStore } from './ModelStore';
4export interface ModelManagerConfiguration {
5 forceReload?: boolean;
6 model?: Model;
7 modelClient?: ModelClient;
8 path?: string;
9}
10export declare type ListenerFunction = () => void;
11export declare class ModelManager {
12 private _modelClient;
13 private _modelStore;
14 private _listenersMap;
15 private _fetchPromises;
16 private _initPromise;
17 private _editorClient;
18 get modelClient(): ModelClient;
19 get modelStore(): ModelStore;
20 /**
21 * Initializes the ModelManager using the given path to resolve a data model.
22 * If no path is provided, fallbacks are applied in the following order:
23 *
24 * - meta property: cq:pagemodel_root_url
25 * - current pathname of the browser
26 *
27 * 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.
28 *
29 * @param {string|InitializationConfig} [config] - URL to the data model or configuration object
30 * @fires cq-pagemodel-loaded
31 * @return {Promise}
32 */
33 initialize<M extends Model>(config?: ModelManagerConfiguration | string): Promise<M>;
34 /**
35 * Returns the path of the data model root.
36 *
37 * @return {string}
38 */
39 get rootPath(): string;
40 /**
41 * Returns the model for the given configuration
42 * @param {string|GetDataConfig} [config] - Either the path of the data model or a configuration object. If no parameter is provided the complete model is returned
43 * @return {Promise}
44 */
45 getData<M extends Model>(config?: ModelManagerConfiguration | string): Promise<M>;
46 /**
47 * Fetches a model for the given path
48 *
49 * @param {string} path - Model path
50 * @return {Promise}
51 * @private
52 */
53 _fetchData(path: string): Promise<Model>;
54 /**
55 * Notifies the listeners for a given path
56 *
57 * @param {string} path - Path of the data model
58 * @private
59 */
60 _notifyListeners(path: string): void;
61 /**
62 * Add the given callback as a listener for changes at the given path.
63 *
64 * @param {String} [path] Absolute path of the resource (e.g., "/content/mypage"). If not provided, the root page path is used.
65 * @param {String} [callback] Function to be executed listening to changes at given path
66 */
67 addListener(path: string | undefined, callback: ListenerFunction): void;
68 /**
69 * Remove the callback listener from the given path path.
70 *
71 * @param {String} [path] Absolute path of the resource (e.g., "/content/mypage"). If not provided, the root page path is used.
72 * @param {String} [callback] Listener function to be removed.
73 */
74 removeListener(path: string | undefined, callback: ListenerFunction): void;
75 /**
76 * Adapts the provided path to a valid model path.
77 * Returns an empty string if the given path is equal to the root model path.
78 * This function is a utility tool that converts a provided root model path into an internal specific empty path
79 *
80 * @param {string} [path] - raw model path
81 * @return {string} the valid model path
82 *
83 * @private
84 */
85 adaptPagePath(path: string): string;
86 /**
87 * @private
88 */
89 private destroy;
90 private _storeData;
91 /**
92 * Transforms the given path into a model URL
93 *
94 * @param path
95 * @return {*}
96 * @private
97 */
98 private _toModelPath;
99 /**
100 * Verifies the integrity of the provided dependencies
101 *
102 * @return {Promise}
103 * @private
104 */
105 private _checkDependencies;
106}
107declare const _default: ModelManager;
108export default _default;
109//# sourceMappingURL=ModelManager.d.ts.map
\No newline at end of file