Uploaded image for project: 'eZ Publish / Platform'
  1. eZ Publish / Platform
  2. EZP-21666

The JS REST client: refactor PromiseCAPI and PromiseService classes

    XMLWordPrintable

Details

    Description

      • this.generatePromiseService can easily be a real private function, as it is only used from within the constructor
      • The same is true for _capi, which may be private to the constructor as well. There is no need to expose either of those information to the outside world.
        In fact there isn't actually the need for a local variable either. The provided argument to the function can easily be used.
      • Each time a service is requested from the PromiseCAPI it is wrapped again. As during a single session (single-page-app) services may be requested multiple times services are singletons inside the CAPI. This behaviour needs to be transfered over to the PromiseCAPI
      • Instead of using string conversions for checking if something really is an array the constructor should
        always be checked as checking for the string does not work in every js environment. (String identifiers are
        not always the same):
        if ( ... && ( this._capi[key].toString().match(/^function\s*(get[^\s(]+Serv
        ice)/).constructor === [].constructor) {
        - Nevertheless in this special case this type of check should not be done
        at all, as changing the call order allows the usage of the ``test``
        method, which is available for exactly this kind of use case::
        if ( ... && (/^function\s*(get[^\s(]+Service)/).test(capi[key].toString
        ())) {
        
      • The before proposed switch to direct (private) variables for all of the functions as well as the capi removes
        the need to use a var that = this construct completely. It may therefore be removed.
      • Mostly all remarks regarding the PromiseCAPI fit for the PromiseService as well. With the exception, that no further cache storage is needed.
      • Especially the remarks on the following topics should be understood with regards to this implementation
        as well:
        + RegExp string check using test
        + Real private variables
        + No need for this._originalService

      Attachments

        Activity

          People

            Unassigned Unassigned
            Anton.Petrushenkov-obsolete@ez.no Anton Petrushenkov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 2 days
                2d