UNPKG

jsf.js_next_gen

Version:

A next generation typescript reimplementation of jsf.js

185 lines 19.9 kB
<!DOCTYPE html><html class="default" lang="en"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>jsf.js_next_gen</title><meta name="description" content="Documentation for jsf.js_next_gen"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="assets/style.css"/><link rel="stylesheet" href="assets/highlight.css"/><script defer src="assets/main.js"></script><script async src="assets/search.js" id="tsd-search-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"</script><header class="tsd-page-toolbar"> <div class="tsd-toolbar-contents container"> <div class="table-cell" id="tsd-search" data-base="."> <div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><path d="M15.7824 13.833L12.6666 10.7177C12.5259 10.5771 12.3353 10.499 12.1353 10.499H11.6259C12.4884 9.39596 13.001 8.00859 13.001 6.49937C13.001 2.90909 10.0914 0 6.50048 0C2.90959 0 0 2.90909 0 6.49937C0 10.0896 2.90959 12.9987 6.50048 12.9987C8.00996 12.9987 9.39756 12.4863 10.5008 11.6239V12.1332C10.5008 12.3332 10.5789 12.5238 10.7195 12.6644L13.8354 15.7797C14.1292 16.0734 14.6042 16.0734 14.8948 15.7797L15.7793 14.8954C16.0731 14.6017 16.0731 14.1267 15.7824 13.833ZM6.50048 10.499C4.29094 10.499 2.50018 8.71165 2.50018 6.49937C2.50018 4.29021 4.28781 2.49976 6.50048 2.49976C8.71001 2.49976 10.5008 4.28708 10.5008 6.49937C10.5008 8.70852 8.71314 10.499 6.50048 10.499Z" fill="var(--color-text)"></path></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div> <div class="field"> <div id="tsd-toolbar-links"></div></div> <ul class="results"> <li class="state loading">Preparing search index...</li> <li class="state failure">The search index is not available</li></ul><a href="index.html" class="title">jsf.js_next_gen</a></div> <div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><rect x="1" y="3" width="14" height="2" fill="var(--color-text)"></rect><rect x="1" y="7" width="14" height="2" fill="var(--color-text)"></rect><rect x="1" y="11" width="14" height="2" fill="var(--color-text)"></rect></svg></a></div></div></header> <div class="container container-main"> <div class="col-content"> <div class="tsd-page-title"> <h2>jsf.js_next_gen</h2></div> <div class="tsd-panel tsd-typography"><a id="md:🚀-scratchpad-for-the-typescript-based-reimplementation-of-jsf-js" class="tsd-anchor"></a><h1><a href="#md:🚀-scratchpad-for-the-typescript-based-reimplementation-of-jsf-js">🚀 Scratchpad for the typescript based reimplementation of jsf js</a></h1><a id="md:what-is-this" class="tsd-anchor"></a><h2><a href="#md:what-is-this">What is this?</a></h2><p>This project is a work in progress for a next gen typescript based reimplementation of jsf.js/faces.js</p> <p>The main goal is maintainability. It omits legacy browsers with Edge 14 and Ecmascript 2015 being the browser and ES baseline for the moment.</p> <p>It uses functional constructs on micro scale to keep the maintainability and uses my own <a href="https://github.com/werpu/mona-dish/">mona-dish</a> project as core framework base, to avoid unnecessary colliding dependencies.</p> <p>But it still uses classes modules and inheritance for code structuring. The reason for this is, I do not like the one function for all approach, especially given we have Typescript now as implementation language which allows a proper code structuring and modularization.</p> <p>Webpack can take care of the packaging.</p> <p>Having smaller code parts, makes it easier to test certain aspects of the implementation.</p> <p>Also one additional aspect of the new implementation: it has a proper test coverage via Mocha based unit tests.</p> <p>This was also severely lacking in my old implementation where I just ran a set of 20 integration tests on macro scale.</p> <a id="md:status" class="tsd-anchor"></a><h2><a href="#md:status">Status</a></h2><p>We now have a stable version! The current stable version (and first stable version is 4.0) Why 4.0 and not 1.0? The reason for this is, it is faces 4.0 compliant (but also faces 2.3 compliant) and also used in MyFaces 4.0. In order to avoid version confusion the projects stable version always will be in sync with the Faces implementation level it provides now and in the future.</p> <a id="md:special-info" class="tsd-anchor"></a><h3><a href="#md:special-info">Special info</a></h3><p>Due to a small api change, if you want to embed the 4.0 version (faces.js) in your code, a new attribute specified by the Faces 4.0 spec is not set at its proper value, <em>contextpath</em>. This attribute atm is a value expression which needs to be set by the loading implementation.</p> <p>Now if you want to provide your own embedded solution and you will have to set this value yourself. While my code does not use the attribute in the faces namespace, other libraries or the users might.</p> <p>If you serve the code from MyFaces 4 instead of embedding it, the value will be preset by the internal resource loader.</p> <p>The JSF 2.3 version (jsf.js) is not affected by this change, so nothing needs to be done. In fact the <em>contextpath</em> attribute is not present there. All other attributes behave the same in both versions as in the original legacy codebase.</p> <a id="md:general-build" class="tsd-anchor"></a><h3><a href="#md:general-build">General build</a></h3><p>run </p> <ul> <li>npm install</li> </ul> <a id="md:on-windows" class="tsd-anchor"></a><h4><a href="#md:on-windows">On Windows</a></h4><p>if not done yet</p> <ul> <li>npm install --global --production windows-build-tools</li> </ul> <p>run</p> <ul> <li>npm install</li> </ul> <a id="md:tests" class="tsd-anchor"></a><h3><a href="#md:tests">Tests</a></h3><p>run</p> <ul> <li>npm test</li> </ul> <a id="md:test-coverage" class="tsd-anchor"></a><h3><a href="#md:test-coverage">Test Coverage</a></h3><ul> <li>npm coverage</li> </ul> <a id="md:changelist-compared-to-the-original-implementation" class="tsd-anchor"></a><h3><a href="#md:changelist-compared-to-the-original-implementation">Changelist compared to the original implementation</a></h3><ul> <li><p><em>no_portlet_env</em> is no more the configuration parameter &#39;no_portlet_env&#39; has become obsolete with jsf 2.3 which introduced a proper namespaced viewstate handling so it is gone now</p> </li> <li><p>pps disabled for the moment</p> </li> </ul> <p>We had a special pps handling introduced in myfaces, a feature probably never used (you basically could reduce the parameters sent down by sending a list of pps ids). I have disabled it for the time being. The code still is in there for the moment, but will be dropped if no demand arises to enable it again.</p> <ul> <li>legacy browsers</li> </ul> <p>In order to improve the maintainability I have dropped a lot of shim and legacy code which was needed to support old browsers. Since our main aim is long term maintainability there is a clear cut. The lowest supported browser for the moment is Edge 14. Older browsers are now cut off. This should suffice for most, if not all important environments. If you still use an older browser than Edge 14 you still can revert to the old codebase for the time being (final cutoff point probably will come within the next few years)</p> <ul> <li>performance</li> </ul> <p>Given that we now have faster browsers and end user devices in the mobile area than 10 years ago and the spec conformity has improved a lot, my main focus was maintainability. Maintainability and readability now comes before performance. So I sacrificed some of the performance to achieve it. Given that the most critical performance hits do not happen in the ajax area this is a sacrifice I can live with, for the time being.</p> <ul> <li>Client side i18n</li> </ul> <p>The client side i18n error message translations have become more of a liability than a feature. For the time being all client side errors are reported in english. I can reintroduce them, if there is real demand. But the size and maintainability tradeoff, compared to what they bring was not worth it to keep them anymore.</p> <ul> <li>Mapping file support</li> </ul> <p>The original implementation had various builds to support easier debugging (split, combined, compressed)</p> <p>We now have only two builds prod and development. However I have introduced a mapping file support. To enable this support you have to reference the FacesJSMappingDecorator unless the mapping file is reachable via the normal request (mapping files are bundled). This works for normal includes, but if you include the jsf.js in a resource library you have to use the decorator provided.</p> <p>Usage <em>faces-config.xml</em></p> <pre><code class="language-xml"><br/><span class="hl-0">&lt;</span><span class="hl-1">application</span><span class="hl-0">&gt;</span><br/><span class="hl-2"> </span><span class="hl-0">&lt;</span><span class="hl-1">resource-handler</span><span class="hl-0">&gt;</span><span class="hl-2">com.example.jsfs_js_ts.FacesJSMapFileResourceWrapper</span><span class="hl-0">&lt;/</span><span class="hl-1">resource-handler</span><span class="hl-0">&gt;</span><br/><span class="hl-0">&lt;/</span><span class="hl-1">application</span><span class="hl-0">&gt;</span> </code><button>Copy</button></pre> <p>This resource decorator detects automatically a faces*.js file coming from a resource library and adjusts the references in the resource accordingly to the request patterns</p> <a id="md:upload-support" class="tsd-anchor"></a><h2><a href="#md:upload-support">Upload Support</a></h2><p>As non standard extension XMLHttpRequestUpload support is added</p> <pre><code class="language-json"><span class="hl-2">faces.ajax.request(document.getElementById(</span><span class="hl-3">&quot;cmd_eval&quot;</span><span class="hl-2">), </span><span class="hl-4">null</span><span class="hl-2">,</span><br/><span class="hl-2">{</span><br/><span class="hl-2"> </span><span class="hl-5">render</span><span class="hl-2">: </span><span class="hl-5">&#39;@form&#39;</span><span class="hl-2">,</span><br/><span class="hl-2"> </span><span class="hl-5">execute</span><span class="hl-2">: </span><span class="hl-5">&#39;@form&#39;</span><span class="hl-2">,</span><br/><span class="hl-2"> </span><span class="hl-5">myfaces</span><span class="hl-2">: {</span><br/><span class="hl-2"> </span><span class="hl-5">upload</span><span class="hl-2">: {</span><br/><span class="hl-2"> </span><span class="hl-5">progress</span><span class="hl-2">: </span><span class="hl-5">(upload:</span><span class="hl-2"> </span><span class="hl-5">XMLHttpRequestUpload</span><span class="hl-2">, </span><span class="hl-5">event</span><span class="hl-2">: </span><span class="hl-5">ProgressEvent)</span><span class="hl-2"> </span><span class="hl-5">=&gt;</span><span class="hl-2"> {</span><br/><span class="hl-2"> </span><span class="hl-5">caughtProgressEvents.push(event);</span><br/><span class="hl-2"> },</span><br/><span class="hl-2"> </span><span class="hl-5">preinit</span><span class="hl-2">: </span><span class="hl-5">(upload:</span><span class="hl-2"> </span><span class="hl-5">XMLHttpRequestUpload)</span><span class="hl-2"> </span><span class="hl-5">=&gt;</span><span class="hl-2"> </span><span class="hl-5">preinitTriggered</span><span class="hl-2"> </span><span class="hl-5">=</span><span class="hl-2"> </span><span class="hl-4">true</span><span class="hl-2">,</span><br/><span class="hl-2"> </span><span class="hl-5">loadstart</span><span class="hl-2">: </span><span class="hl-5">(upload:</span><span class="hl-2"> </span><span class="hl-5">XMLHttpRequestUpload</span><span class="hl-2">, </span><span class="hl-5">event</span><span class="hl-2">: </span><span class="hl-5">ProgressEvent)</span><span class="hl-2"> </span><span class="hl-5">=&gt;</span><span class="hl-2"> </span><span class="hl-5">loadstartTriggered</span><span class="hl-2"> </span><span class="hl-5">=</span><span class="hl-2"> </span><span class="hl-4">true</span><span class="hl-2">,</span><br/><span class="hl-2"> </span><span class="hl-5">load</span><span class="hl-2">: </span><span class="hl-5">(upload:</span><span class="hl-2"> </span><span class="hl-5">XMLHttpRequestUpload</span><span class="hl-2">, </span><span class="hl-5">event</span><span class="hl-2">: </span><span class="hl-5">ProgressEvent)</span><span class="hl-2"> </span><span class="hl-5">=&gt;</span><span class="hl-2"> </span><span class="hl-5">loadTriggered</span><span class="hl-2"> </span><span class="hl-5">=</span><span class="hl-2"> </span><span class="hl-4">true</span><span class="hl-2">,</span><br/><span class="hl-2"> </span><span class="hl-5">loadend</span><span class="hl-2">: </span><span class="hl-5">(upload:</span><span class="hl-2"> </span><span class="hl-5">XMLHttpRequestUpload</span><span class="hl-2">, </span><span class="hl-5">event</span><span class="hl-2">: </span><span class="hl-5">ProgressEvent)</span><span class="hl-2"> </span><span class="hl-5">=&gt;</span><span class="hl-2"> </span><span class="hl-5">loadendTriggered</span><span class="hl-2"> </span><span class="hl-5">=</span><span class="hl-2"> </span><span class="hl-4">true</span><span class="hl-2">,</span><br/><span class="hl-2"> </span><span class="hl-5">error</span><span class="hl-2">: </span><span class="hl-5">(upload:</span><span class="hl-2"> </span><span class="hl-5">XMLHttpRequestUpload</span><span class="hl-2">, </span><span class="hl-5">event</span><span class="hl-2">: </span><span class="hl-5">ProgressEvent)</span><span class="hl-2"> </span><span class="hl-5">=&gt;</span><span class="hl-2"> </span><span class="hl-5">errorTriggered</span><span class="hl-2"> </span><span class="hl-5">=</span><span class="hl-2"> </span><span class="hl-4">true</span><span class="hl-2">,</span><br/><span class="hl-2"> </span><span class="hl-5">abort</span><span class="hl-2">: </span><span class="hl-5">(upload:</span><span class="hl-2"> </span><span class="hl-5">XMLHttpRequestUpload</span><span class="hl-2">, </span><span class="hl-5">event</span><span class="hl-2">: </span><span class="hl-5">ProgressEvent)</span><span class="hl-2"> </span><span class="hl-5">=&gt;</span><span class="hl-2"> </span><span class="hl-5">abortTriggered</span><span class="hl-2"> </span><span class="hl-5">=</span><span class="hl-2"> </span><span class="hl-4">true</span><span class="hl-2">,</span><br/><span class="hl-2"> </span><span class="hl-5">timeout</span><span class="hl-2">: </span><span class="hl-5">(upload:</span><span class="hl-2"> </span><span class="hl-5">XMLHttpRequestUpload</span><span class="hl-2">, </span><span class="hl-5">event</span><span class="hl-2">: </span><span class="hl-5">ProgressEvent)</span><span class="hl-2"> </span><span class="hl-5">=&gt;</span><span class="hl-2"> </span><span class="hl-5">timeoutTriggered</span><span class="hl-2"> </span><span class="hl-5">=</span><span class="hl-2"> </span><span class="hl-4">true</span><span class="hl-2">,</span><br/><span class="hl-2"> }</span><br/><span class="hl-2"> }</span><br/><span class="hl-2">});</span> </code><button>Copy</button></pre> <a id="md:changes-since-40" class="tsd-anchor"></a><h2><a href="#md:changes-since-40">Changes since 4.0</a></h2><ul> <li>Elimination of Streams in favor of native arrays</li> <li>Providing an internal non intrusive shim for browsers which do not have array map and flapMap (older Edge and Chromium versions) - done in mona-dish</li> <li>Adding a progress monitoring functionality under the myfaces namespace</li> <li>Bugfixes which improve tck compliance</li> <li>Integration in myfaces 4.0+ as default faces.js implementation</li> </ul> </div></div> <div class="col-sidebar"> <div class="page-menu"> <div class="tsd-navigation settings"> <details class="tsd-index-accordion"><summary class="tsd-accordion-summary"> <h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><path d="M4.93896 8.531L12 15.591L19.061 8.531L16.939 6.409L12 11.349L7.06098 6.409L4.93896 8.531Z" fill="var(--color-text)" id="icon-chevronDown"></path></svg>Settings</h3></summary> <div class="tsd-accordion-details"> <div class="tsd-filter-visibility"> <h4 class="uppercase">Member Visibility</h4><form> <ul id="tsd-filter-options"> <li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li></ul></form></div> <div class="tsd-theme-toggle"> <h4 class="uppercase">Theme</h4><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div> <details open class="tsd-index-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"> <h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="#icon-chevronDown"></use></svg>On This Page</h3></summary> <div class="tsd-accordion-details"> <ul> <li> <ul> <li><a href="#md:🚀-scratchpad-for-the-typescript-based-reimplementation-of-jsf-js"><span>🚀 <wbr/>Scratchpad for the typescript based reimplementation of jsf js</span></a></li> <li> <ul> <li><a href="#md:what-is-this"><span>What is this?</span></a></li> <li><a href="#md:status"><span>Status</span></a></li> <li> <ul> <li><a href="#md:special-info"><span>Special info</span></a></li> <li><a href="#md:general-build"><span>General build</span></a></li> <li> <ul> <li><a href="#md:on-windows"><span>On <wbr/>Windows</span></a></li></ul></li> <li><a href="#md:tests"><span>Tests</span></a></li> <li><a href="#md:test-coverage"><span>Test <wbr/>Coverage</span></a></li> <li><a href="#md:changelist-compared-to-the-original-implementation"><span>Changelist compared to the original implementation</span></a></li></ul></li> <li><a href="#md:upload-support"><span>Upload <wbr/>Support</span></a></li> <li><a href="#md:changes-since-40"><span>Changes since 4.0</span></a></li></ul></li></ul></li></ul></div></details></div> <div class="site-menu"> <nav class="tsd-navigation"><a href="modules.html" class="current"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><g id="icon-4"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-namespace)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><path d="M9.33 16V7.24H10.77L13.446 14.74C13.43 14.54 13.41 14.296 13.386 14.008C13.37 13.712 13.354 13.404 13.338 13.084C13.33 12.756 13.326 12.448 13.326 12.16V7.24H14.37V16H12.93L10.266 8.5C10.282 8.692 10.298 8.936 10.314 9.232C10.33 9.52 10.342 9.828 10.35 10.156C10.366 10.476 10.374 10.784 10.374 11.08V16H9.33Z" fill="var(--color-text)"></path></g></svg><span>jsf.js_<wbr/>next_<wbr/>gen</span></a> <ul class="tsd-small-nested-navigation"> <li><a href="modules/faces.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>faces</span></a></li> <li><a href="modules/myfaces.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>myfaces</span></a></li></ul></nav></div></div></div> <div class="tsd-generator"> <p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></div> <div class="overlay"></div></body></html>