Skip to content

Instantly share code, notes, and snippets.

@tomodutch
Created September 17, 2015 16:30
Show Gist options
  • Save tomodutch/e8b35f72fadc75eb7aac to your computer and use it in GitHub Desktop.
Save tomodutch/e8b35f72fadc75eb7aac to your computer and use it in GitHub Desktop.
Meteor-polymer
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();
});
}
<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>
<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