UNPKG

3.89 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _propTypes = require('prop-types');
8
9var _propTypes2 = _interopRequireDefault(_propTypes);
10
11var _AbstractPureComponent = require('./AbstractPureComponent');
12
13var _AbstractPureComponent2 = _interopRequireDefault(_AbstractPureComponent);
14
15var _MetaManager = require('../meta/MetaManager');
16
17var _MetaManager2 = _interopRequireDefault(_MetaManager);
18
19function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
21const PRIVATE = {
22 masterElementId: Symbol('masterElementId')
23};
24
25if (typeof $Debug !== 'undefined' && $Debug) {
26 Object.freeze(PRIVATE);
27}
28
29// @server-side class AbstractDocumentView extends __VARIABLE__ {__CLEAR__}\nexports.default = AbstractDocumentView;
30
31/**
32 * The base class for document view components. The document view components
33 * create the basic markup, i.e. the {@code html} or {@code head} elements,
34 * along with an element that will contain the view associated with the current
35 * route.
36 *
37 * Note that the document views are always rendered only at the server-side and
38 * cannot be switched at the client-side. Because of this, the document view
39 * component must be pure and cannot contain a state.
40 *
41 * @abstract
42 */
43class AbstractDocumentView extends _AbstractPureComponent2.default {
44 /**
45 * Returns the ID of the element (the value of the {@code id} attribute)
46 * generated by this component that will contain the rendered page view.
47 *
48 * @abstract
49 * @return {string} The ID of the element generated by this component that
50 * will contain the rendered page view.
51 */
52 static get masterElementId() {
53 if (this[PRIVATE.masterElementId] !== undefined) {
54 return this[PRIVATE.masterElementId];
55 }
56
57 throw new Error('The masterElementId getter is abstract and must be overridden');
58 }
59
60 /**
61 * Setter for the ID of the element (the value of the {@code id} attribute)
62 * generated by this component that will contain the rendered page view.
63 *
64 * This setter is used only for compatibility with the public class fields
65 * and can only be used once per component.
66 *
67 * @param {string} masterElementId The ID of the element generated by this
68 * component that will contain the rendered page view.
69 */
70 static set masterElementId(masterElementId) {
71 if ($Debug) {
72 if (this[PRIVATE.masterElementId] !== undefined) {
73 throw new Error('The masterElementId can be set only once and cannot be ' + 'reconfigured');
74 }
75 }
76
77 this[PRIVATE.masterElementId] = masterElementId;
78 }
79
80 /**
81 * Returns the expected types of the props passed to this component.
82 *
83 * The {@code metaManager} is used to generate the {@code meta} tags in the
84 * {@code head} and the content of the {@code title} element. The
85 * {@code page} contains the rendered HTML of the current view. The
86 * {@code revivalSettings} contains a JavaScript snippet that initializes
87 * the configuration of the IMA platform at the client-side.
88 *
89 * @return {{metaManager: *, page: *, revivalSettings: *}} The expected
90 * types of the props passed to this component.
91 */
92 static get propTypes() {
93 return {
94 metaManager: _propTypes2.default.instanceOf(_MetaManager2.default).isRequired,
95 page: _propTypes2.default.string.isRequired,
96 revivalSettings: _propTypes2.default.string.isRequired,
97 $Utils: _propTypes2.default.object.isRequired
98 };
99 }
100
101 /**
102 * @inheritdoc
103 */
104 static get contextTypes() {
105 return {};
106 }
107}
108exports.default = AbstractDocumentView;
109
110typeof $IMA !== 'undefined' && $IMA !== null && $IMA.Loader && $IMA.Loader.register('ima/page/AbstractDocumentView', [], function (_export, _context) {
111 'use strict';
112 return {
113 setters: [],
114 execute: function () {
115 _export('default', exports.default);
116 }
117 };
118});