Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-115990

As a developer I'd have a consistent Javascript environment for SPA and Fragments development

Details

    Description

      I'm recently working on a PoC project in Liferay 7.3.2 CE GA3 and I noticed that the javascript API is quite outdated and does not fit very well the modern Liferay environment.

      There are 3 events that get executed for SPA navigation (beforeNavigate, startNavigate and endNavigate) but not when a user accesses the page directly. On the other hand, there are the old AUI().ready(..)Liferay.Portlet.ready(...) and Liferay.on('allPortletsReady', ...) which work well for classic portlet development but not for fragments. It would be great if we could have a consistent API to develop small javascript apps in fragments, that can be registered once a user enters a page (regardless if it's via SPA navigation or directly), have their own context and be disposed of when a user leaves the page via SPA. It is especially important for scripts that use global browser events like "scroll" event listener, or when using standard bootstrap javascript features.

      Below is the list of my suggestions that I think would help developers work on javascript in Fragment/SPA environment:

      • The "document" variable is global and shared across all the pages in SPA environment so it would be great to have a similar variable that is created once a user visits a specific page and then disposed of when a user leaves it.
      • A common callback method to allow a developer to init his code once the page is fully loaded. Similar to AUI().ready(..), but also working consistently in Fragment edit mode.
      • A common callback method to dispose all the unnecessary objects and unregister all global events and handlers that were added once a user initially entered the page. The difference from a similar beforeNavigate event is that this callback method would be executed only once a user leaves this specific page would not remain registered for the entire SPA session.
      • An easy way to distinguish if we're currently in an edit mode (that is already described in https://issues.liferay.com/browse/LPS-115828, based on the discussion https://liferay.dev/forums/-/message_boards/view_message/119449736)

       

       

       

      Attachments

        Activity

          People

            mateo.hermosin Mateo Hermosin
            kgolebiowski Krzysztof Gołębiowski
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Packages

                Version Package