Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-4739

Improve pdfviewer component by making each promise level override-accessible

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Done
    • Icon: Normal Normal
    • 9.5.1
    • 9.0.0
    • Components
    • Security Level: Jimmy
    • ZK 9.5.1 S1

      Current state

      The pdfviewer component contains inline lambdas used in promises.

      This makes overrides very difficult / impossible without replacing the whole JS file due to the code being unreachable in client.

      Ex: zkex/pdfviewer/Pdfviewer.ts

      _getPage(pageNum) has a structure such as:

       

      _getPage(pageNum: number, pdfFirstRender = false) {
                      ...
      		return this._pdf.getPage(pageNum).then(page => {
                              ...
      			return page.render({...})
      				.promise
      				.then(() => page.getTextContent({}))
      				.then(textContent => {
                              ...
      

       

      Desired state

      Instead of using inline promises, the promise could access a function defined at class level.
      ex:

      _getPage(pageNum: number, pdfFirstRender = false) {
                      ...
      		return this._pdf.getPage(pageNum).then(promiseGetPageAfterPdfGetPage);
      
      //end of instance-level function, start of class-level functions
      },{ 
          promiseGetPageAfterPdfGetPage: function (page) {
              ...
              return page.render({...})
      				.promise
      				.then(promiseGetPageGetTextContent)
          },
          promiseGetPageGetTextContent: function(){
              ...
          }
      
      }
      

       
      etc.

      This would allow developers to set overrides granularly without having to replace the whole JS file.

      Workaround

      Compile and replace the whole pdfviewer.tf source by the updated replacement. 

            rudyhuang rudyhuang
            MDuchemin MDuchemin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 4 hours
                4h
                Remaining:
                Time Spent - 2 hours Remaining Estimate - 2 hours
                2h
                Logged:
                Time Spent - 2 hours Remaining Estimate - 2 hours
                2h