zhouzhuojie / meteor-vue

Vue for Meteor
130 stars 8 forks source link

a problem with sync #2

Closed wuxianliang closed 10 years ago

wuxianliang commented 10 years ago

Dear Zhou: I am using meteor-vue with meteor 0.9.4 to reproduce todomvc and meet a problem: after coding sync: { todotoday: function () { startofDay = moment().startOf('day').format('YYYY-MM-DDTHH:mm:ss.SSSZ'); endofDay = moment().startOf('day').add(1, 'days').format('YYYY-MM-DDTHH:mm:ss.SSSZ'); return todos.find({start: {$gt: startofDay, $lt: endofDay}}); } }, the v-model:"completed" does change on the client side, but server side. It looks like "read only". Could you please have a try? Thank you very much.

zhouzhuojie commented 10 years ago

Indeed, this problem is related to three-way binding. For example,

v-model: ... <----> vue instance <----> Meteor Collection

Are you suggesting that if we change the v-model, the new value should be inserted or updated to the vue instance and Meteor collections? From practical and security standpoint, we encourage users to use vue's methods or Meteor call() to update or insert data to the databases, and the logic of running this belongs to the userland. Otherwise, meteor-vue needs to define which collection to sync with the v-model, and it seems too cumbersome and opinionated for a package.

A naive example from my understanding:

var vm = new Vue({
    data: {
        completed: false
    },
    methods: {
        onClick: function (e) {
            Meteor.call('actionComplete', someTodos);
        }
    }
});

And then you can bind the v-on= "click: onClick" on the input tag.

wuxianliang commented 10 years ago

Thank you very much. I misunderstood the word "sync".