Created
September 17, 2015 16:30
-
-
Save tomodutch/e8b35f72fadc75eb7aac to your computer and use it in GitHub Desktop.
Meteor-polymer
This file contains hidden or 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
Tasks = new Mongo.Collection('tasks'); | |
if (Meteor.isServer) { | |
Tasks.insert({ | |
text: 'hey' | |
}); | |
Meteor.publish('tasks', function () { | |
console.log('connected'); | |
var tasks = Tasks.find().fetch(); | |
console.log(tasks); | |
return Tasks.find(); | |
}); | |
} |
This file contains hidden or 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
<dom-module id="todo-list"> | |
<template> | |
<style> | |
:host { | |
display: block; | |
} | |
</style> | |
<todo-store tasks="{{tasks}}"></todo-store> | |
<ul> | |
<template is="dom-repeat" items="[[tasks]]"> | |
<li>[[item.text]]</li> | |
</template> | |
</ul> | |
</template> | |
<script> | |
(function() { | |
'use strict'; | |
Polymer({ | |
is: 'todo-list', | |
}); | |
})(); | |
</script> | |
</dom-module> |
This file contains hidden or 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
<script src="../../bower_components/ddp.js/src/ddp.js"></script> | |
<script src="../../bower_components/q/q.js"></script> | |
<script src="../../bower_components/asteroid/dist/asteroid.browser.js"></script> | |
<dom-module id="todo-store"> | |
<template> | |
</template> | |
<script> | |
(function() { | |
'use strict'; | |
Polymer({ | |
is: 'todo-store', | |
properties: { | |
tasks: { | |
type: Array, | |
notify: true | |
} | |
}, | |
ready: function() { | |
var client = new Asteroid('localhost:3000'); | |
var subscription = client.subscribe('tasks'); | |
subscription.ready.then(function() { | |
var collection = client.getCollection('tasks'); | |
var query = collection.reactiveQuery({}); | |
query.on('change', function() { | |
this.tasks = query.result; | |
}.bind(this)); | |
this.tasks = query.result; | |
}.bind(this)).catch(function(err) { | |
console.log(err); | |
}); | |
} | |
}); | |
})(); | |
</script> | |
</dom-module> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment