I´m currently starting with Polymerfire and trying to do a small application to list some data stored on Firebase as a paper-card. I have used some of the code from the google labs example to build up the application so its stands as follow:
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
<title>Beer Cellar</title>
<link rel="manifest" href="manifest.json">
<style>
body {
margin: 0;
}
</style>
<script src="bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="bower_components/polymerfire/firebase-app.html">
<link rel="import" href="beer-list-app.html">
</head>
<body>
<firebase-app
name="BeerCellar"
api-key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
auth-domain="beercellar-627fc.firebaseapp.com"
database-url="https://beercellar-627fc.firebaseio.com">
</firebase-app>
<beer-list-app></beer-list-app>
</body>
</html>
beer-list-app.html
<link rel="import" href="bower_components/polymerfire/polymerfire.html">
<link rel="import" href="bower_components/paper-card/paper-card.html">
<dom-module id="beer-list-app">
<template>
<firebase-query
id="query"
log
app-name="BeerCellar"
path="/brands"
data="{{branddata}}">
</firebase-query>
<template is="dom-repeat" items="[[branddata]]" as="brand">
<paper-card heading="[[brand.name]]">
<div class="card-content">[[brand.origin]]</div>
</paper-card>
</template>
</template>
<script>
Polymer({
is: 'beer-list-app',
properties: {
uid: String,
branddata: {
type: Object,
observer: 'dataChanged'
}
},
dataChanged: function (newData, oldData) {
// do something when the query returns values
console.log("NewData: " + newData);
}
});
</script>
</dom-module>
However it appears that is not working and not showing anything. I´ve added the log property to the firebase-query and got the following on the console:
Initializing stored value.
polymer-micro.html:673 Polymer::Attributes: couldn`t decode Array as JSON
app-storage-behavior.html:350 Got stored value! undefined {{branddata}}
I´ve tried changing items on template to [[branddata]] with the same result.
The code of polymer-micro.html in which the error is throwing:
deserialize: function (value, type) {
switch (type) {
case Number:
value = Number(value);
break;
case Boolean:
value = value != null;
break;
case Object:
try {
value = JSON.parse(value);
} catch (x) {
}
break;
case Array:
try {
value = JSON.parse(value);
} catch (x) {
value = null;
console.warn('Polymer::Attributes: couldn`t decode Array as JSON');
}
break;
According to Chrome dev tools the variable value for JSON.parse contains {{branddata}} or [[branddata]] depending on how I´ve defined it on the template.
It´s there something I´m missing.
Edit: I changed a little bit beer-list-app.html adding the dom-module. Now the json error has dissappeared and the log appears as follows:
Initializing stored value.
beer-list-app.html:33 BrandData:
app-storage-behavior.html:350 Got stored value! undefined []
Edit 2: I modified the code from data-changed function in beer-list-app.html as getbuckts suggested. My console logs the newData as empty.
Thanks in advance.