Description
The Problem
There seems to be an issue binding complex objects w/ Polymer than what I'm familar with. I'm using the latest version of polymer
, as well as platform.js
.
What I mean by 'complex objects'
I'm familiar creating web components natively that can bind to complex objects as the model it supports as shown below:
index.html
<template bind={{ supermodel }}>
<div> {{supermodel.name}}</div>
</template>
main.coffee
template = document.querySelector('template');
# Check if the template element is properly supported in the current browser enviroment I'm currently developing this element on
if 'content' in template
template.model = {
supermodel:
name: "Kate Upton"
}
# For Non-Chrome Browsers
Platform.performMicrotaskCheckPoint()
else
console.log "Basic <template></template> support is failing, I have to replace this with a proper fallback. "
*Of course, this is not enough since I would have create a prototype for the new element that inherits from HTMLElementPrototype
and document.register
to register the x-supermodel
element as a valid element instead of HTMLUnknownElement
*
Detailed explanation of the problem
With the latest version of Polymer, creating elements for basic types is straightforward as always:
index.haml
%polymer-element{ name: "x-supermodel", attributes: "name"}
%template
%span {{ name }}
%script{src: "scripts/elements/supermodel_basic.js"}
%x-supermodel{name: "Kate Upton"}
supermodel_basic.coffee (works)
Polymer('x-supermodel', name: "Unnamed Model")
However, the following should work, but doesn't when attempting to bind a complex object:
index.haml
%polymer-element{ name: "x-supermodel", attributes: "name supermodel"}
%template
%span {{ supermodel.name }}
%script{src: "scripts/elements/supermodel.js"}
%x-supermodel{name: "Kate Upton"}
supermodel.coffee (doesn't work)
Polymer 'x-supermodel', {
created: ->
@supermodel = { name: "Unnamed Model" }
}
According to Chris Buckett (author of Web Components in Action), this pattern should work to bind a complex object & instances of polymer-element
together. Did the latest version(s) of Polymer change the way complex objects can be binded as a model?