Created
June 23, 2015 19:02
-
-
Save niallobrien/6cb8390dfbc2d2ef1ed3 to your computer and use it in GitHub Desktop.
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
Template.todo.onCreated(function() { | |
var template = this; | |
template.limit = new ReactiveVar(5); | |
}); | |
Template.todo.rendered = function () { | |
var template = this; | |
Vue.use(window['vue-validator']); | |
var vm = new Vue({ | |
el: '#demo', | |
data: { | |
title: 'todos', | |
todos: [], | |
newTodo: '', | |
limit: template.limit.get(), | |
loading: false | |
}, | |
methods: { | |
addTodo: function (e) { | |
e.preventDefault() | |
if (this.newTodo.trim()) { | |
Meteor.call('addTodo', this.newTodo) | |
this.newTodo = '' | |
} | |
}, | |
removeTodo: function (id) { | |
Meteor.call('removeTodo', id) | |
}, | |
loadMore: function() { | |
console.log(template.subscriptionsReady()); | |
Meteor.setTimeout(function() { | |
template.limit.set(template.limit.get() + 5) | |
}, 5000) | |
}, | |
}, | |
created: function () { | |
this.subscription = Meteor.subscribe('todos', function() { | |
}); | |
}, | |
sync: { | |
'todos': function() { | |
return Todos.find({}, {limit: template.limit.get()}); | |
}, | |
'loading': function() { | |
return template.subscriptionsReady(); | |
} | |
}, | |
destroyed: function () { | |
this.subscription.stop() | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment