Skip to content

Instantly share code, notes, and snippets.

@semateos
Created October 15, 2014 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save semateos/f06c70075dc3fb7d79ce to your computer and use it in GitHub Desktop.
Save semateos/f06c70075dc3fb7d79ce to your computer and use it in GitHub Desktop.
polymer lazy loading fail
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<title>polymer import</title>
<script src="/bower_components/platform/platform.js"></script>
<link rel="import" href="/bower_components/polymer/polymer.html">
</head>
<body unresolved>
<polymer-element name="demo-app" attributes="session">
<template>
<h1>Parent: {{session.id}}</h1>
<input type="text" value="{{session.id}}">
<button on-tap="{{buttonClick}}">Test Import</button>
<lazy-test id="test"></lazy-test>
</template>
<script>
Polymer({
elementLoaded: function(e) {
console.log('elementLoaded');
var self = self;
var test = this.$.test;
test.addEventListener('ready', function(){
console.log('elementReady');
/*
test.session = self.session;
test.bind('session', new PathObserver(self, 'session'));
self.bind('session', new PathObserver(test, 'session'));
*/
});
},
buttonClick: function(e){
console.log('buttonClick');
Polymer.import( ['lazy-test.html'], function() {
console.log('lazy-test.html loaded');
this.elementLoaded();
}.bind(this));
},
sessionChanged: function(){
console.log('parent sessionChange', this.session);
},
ready: function(){
window.addEventListener('WebComponentsReady', function(e) {
console.log('WebComponentsReady');
});
var self = this;
window.setTimeout(function(){
self.session = {id: '321'};
}, 3000);
},
created: function() {
// hint that session is an object
this.session = {};
}
});
</script>
</polymer-element>
<demo-app session='{"id": "123"}'></demo-app>
</body>
</html>
<link rel="import" href="/bower_components/polymer/polymer.html">
<polymer-element name="lazy-test" attributes="session">
<template>
<h1>Child: {{session.id}}</h1>
<input type="text" value="{{session.id}}">
</template>
<script>
Polymer({
created: function() {
// hint that session is an object
this.session = {};
},
ready: function(){
this.fire('ready');
},
sessionChanged: function(){
console.log('child sessionChange', this.session);
},
});
</script>
</polymer-element>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment