又一次尝试将 Polymer 与 ES6 类结合起来。
它几乎可以工作,除了 wct 测试在具有导入的 es6 类(通过 systemjs)的聚合物组件上随机失败。据我了解,这是因为包含类定义的脚本在 mocha 执行测试后被加载。聚合物组件由两部分组成 - html 和 javascript(将后者编译为 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
}
});
这似乎在浏览器中工作得相当稳定,至少在从 localhost 加载时是这样。但唯一“修复”测试的是延迟 Polymer 的就绪调用:
Polymer.whenReady = function (f) {
console.log("polymer ready");
setTimeout(f, 100);// "fix"
//f();
}
这意味着在某些时候,所有这些都将在浏览器中失败(可能不是从本地主机提供服务时)。
我正在考虑以某种方式获得系统注册的承诺并制作类似于 HTMLImports.whenDocumentReady 的东西,但我仍然不清楚这一切是如何工作的。
因此,非常感谢任何想法和建议!
示例应用程序在 github 上:
git clone https://github.com/bushuyev/test_test.git
cd test_test
git checkout tags/random_fail
npm install
bower install
gulp wct
为了使其成功多于失败 - 在 wct.conf.js 中将 verbose 更改为 true。
更新类型:如何导入系统 js SFX 库