Source: portlet/register.es.js

  1. /**
  2. * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or modify it under
  5. * the terms of the GNU Lesser General Public License as published by the Free
  6. * Software Foundation; either version 2.1 of the License, or (at your option)
  7. * any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  12. * details.
  13. */
  14. import PortletInit from './PortletInit.es';
  15. import {validateArguments, validatePortletId} from './portlet_util.es';
  16. /**
  17. * Registers a portlet client with the portlet hub.
  18. * @param {string} portletId The unique portlet identifier
  19. * @return {Promise} A Promise object. Returns an {@link PortletInit} object
  20. * containing functions for use by the portlet client on successful resolution.
  21. * Returns an Error object containing a descriptive message on failure.
  22. * @review
  23. */
  24. const register = function (portletId) {
  25. validateArguments(arguments, 1, 1, ['string']);
  26. const pageRenderState = global.portlet.data.pageRenderState;
  27. return new Promise((resolve, reject) => {
  28. if (validatePortletId(pageRenderState, portletId)) {
  29. resolve(new PortletInit(portletId));
  30. }
  31. else {
  32. reject(new Error('Invalid portlet ID'));
  33. }
  34. });
  35. };
  36. export {register};
  37. export default register;