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

Teach Liferay.State.subscribe to optionally read immediately

    Details

    • Type: Task
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: JS APIs and Utilities
    • Labels:
      None

      Description

      WISHLIST ITEM — We don't yet have an immediate need for this, but it is an obvious potential improvement, so I want to make a note of it.

      Sibling issue to:

      When we were studying the list of SPA/Senna events (LPS-127083, Google doc) we noted that it might be convenient to be able to read state immediately in addition to subscribing to it.

      That is, in places where you might do something like this (ie. do some initial set-up immediately, and then prepare to handle later updates):

      const value = Liferay.State.readAtom(atom);
      
      doSomeSetup(value);
      
      const {dispose} = Liferay.State.subscribe(atom, (value) => {
          doSomeUpdate(value);
      });

      You might instead find it convenient to do: 

      const {dispose} = Liferay.State.subscribe(atom, {eager: true}, (value) => {
         doSetupOrUpdate(value);
      });

      Note that this is suitable for contexts in which the initial setup and the subsequent updates are basically equivalent, so you don't actually need separate options for them.

      Now, the above API is only a sketch. We have other options, including but not necessarily limited to:

      • Different names or forms for the eager option; could be readImmediately: true or read: 'immediate' etc.
      • Changing argument order: instead of allowing options to be passed as a second param (would require us to be polymorphic on that param type), we could pass it as a third.
      • Instead of doing this via an option, add a completely separate method, like Liferay.State.subscribeEager (or similar). Note the big drawback of this method is that if ever want to add a second option, we will either have to implement it in both methods, or create a messy set of methods that represent combinations of options.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              support-lep@liferay.com SE Support
              Reporter:
              greg.hurrell Greg Hurrell (Inactive)
              Recent user:
              Greg Hurrell (Inactive)
              Participants of an Issue:
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:

                  Packages

                  Version Package