Random test using polymer web component

Another attempt to marry Polymer with ES6 classes.

And it almost works, except that the wct test accidentally fails on a polymer component with an imported es6 class (by systemjs). As I understand it, this is because the script containing the class definition is loaded after the mocha has run the test. The polymer component consists of two parts: html and javascript (to compile the latter with es5),

HTML:

<dom-module id="my-test">
   <template>hello</template>
   <script>
      System.import('elements/my-test.js');
   </script>
</dom-module>

      

JavaScript:

import {User} from 'elements/model/user.js';

Polymer({
 is: "my-test",

 method: function(){
   console.log("method, user="+this.val);
 },

 ready: function(){
   this.user= new User(); //this.user is randomly undefined
 }
});

      

This seems to work pretty stable in the browser, at least when downloading from localhost. But the only thing that "fixes the test" is the postponement of the call to "Polymers":

Polymer.whenReady = function (f) {
   console.log("polymer ready");
   setTimeout(f, 100);// "fix"
   //f();
}

      

which means that at some point all of this will fail in the browser as well (possibly when serving from outside of localhost).

It seems to me that I somehow got into the promises system registers and did something similar to HTMLImports.whenDocumentReady, but I still don't have a clear understanding of how it all works.

Therefore, any ideas and suggestions are greatly appreciated!

An example app is on github:

git clone https://github.com/bushuyev/test_test.git
cd test_test
git checkout tags/random_fail
npm install
bower install
gulp wct

      

To make it more successful than failing, change verbose to true in wct.conf.js.

update kind: How to import SFX library of js system

+3


source to share


1 answer


It is possible to use Polymer, SystemJS and TypeScript (like ES6, but with added Polymer compatible syntax) together very nicely, also handling HTML imports with SystemJS. This is due to a timing issue, and I posted a little shim that first waits for webcomponents.js to load and find its ready event (before other code gets a chance to see it), then loads Polymer, and finally all the other components and TypeScript code. Then it dispatches the event again so that Polymer completes initialization.



Here's an article on combining technologies with the specified solution, downloadable code, and demo.

+1


source







All Articles