Created
July 13, 2014 10:05
-
-
Save suzuki0keiichi/a78a8c361f6bb0a52aa9 to your computer and use it in GitHub Desktop.
Polymerのcore-listサンプルがdefinePropertyだと動かない件
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<!-- | |
Copyright (c) 2014 The Polymer Project Authors. All rights reserved. | |
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt | |
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | |
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt | |
Code distributed by Google as part of the polymer project is also | |
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt | |
--> | |
<html> | |
<head> | |
<title>core-list</title> | |
<meta name="viewport" content="width=device-width"> | |
<script src="bower_components/platform/platform.js"></script> | |
<link rel="import" href="bower_components/core-list/core-list.html"> | |
<style> | |
html, body { | |
height: 100%; | |
margin: 0; | |
} | |
list-test { | |
display: block; | |
height: 100%; | |
margin: 0 auto; | |
} | |
.stuff { | |
min-height: 60px; | |
background: red !important; | |
border-bottom: 1px solid black; | |
} | |
</style> | |
</head> | |
<body> | |
<list-test></list-test> | |
<polymer-element name="list-test"> | |
<template> | |
<style> | |
core-list { | |
height: 100%; | |
} | |
.item { | |
box-sizing: border-box; | |
height: 80px; | |
border-bottom: 1px solid #ddd; | |
padding: 4px; | |
cursor: default; | |
background-color: white; | |
overflow: hidden; | |
} | |
.selected { | |
background: silver; | |
} | |
.message { | |
padding-left: 77px; | |
line-height: 167%; | |
background-repeat: no-repeat; | |
background-position: 10px 10px; | |
background-size: 60px; | |
} | |
.from { | |
display: inline; | |
font-weight: bold; | |
} | |
.timestamp { | |
margin-left: 10px; | |
font-size: 12px; | |
opacity: 0.8; | |
} | |
.body { | |
font-size: 12px; | |
} | |
</style> | |
<core-list id="list" data="{{data}}" height="80"> | |
<template> | |
<div class="item {{ {selected: selected} | tokenList }}"> | |
<div class="message" style="background-image: url(images/{{index % 4}}.png);"> | |
<span class="from">{{name}}</span> | |
<span class="timestamp">{{time}}</span> | |
<div class="subject">Infinite List. {{index}}</div> | |
<div class="body">{{details}}</div> | |
</div> | |
</div> | |
</template> | |
</core-list> | |
</template> | |
<script> | |
(function() { | |
var foo = {data: [ | |
{index: 0, name: "hello", divider: "h", details: "fewga", time: '8:29pm'}, | |
{index: 1, name: "2hello", divider: "2", details: "fewga", time: '8:29pm'} | |
]}; | |
var Baz = function() {}; | |
Object.defineProperty(Baz.prototype, "data", { | |
set: function(val) {}, | |
get: function() { return foo.data; }, | |
enumerable: true | |
}); | |
var bar = new Baz(); | |
// どっちも表示される中身は一緒なのに | |
console.log(foo.data); | |
console.log(bar.data); | |
// こっちはうまく行く | |
Polymer("list-test", foo); | |
// こっちはうまく行かない | |
Polymer("list-test", bar); | |
})(); | |
</script> | |
</polymer-element> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
改変元はこれ。
https://github.com/Polymer/core-list/blob/master/demo.html
Scala.jsがat JSExportで定義するとdefinePropertyで宣言してしまうため、これを拾ってくれないとPolymer連携ができない。