[Vuejs]-How to best implement model delta (PUT/PATCH) in vue.js?

-1👍

Maybe you can use something like:

var app = new Vue({
        el: "#root",
        data: {
            a: 10,
            b: 20,
            c: {
                loveJS: true,
                vue: "isAwesome"
            }
        },
        methods: {
            track: (function(history){
                return function(n){
                    history.push(n)
                    console.log(history)
                }
            })([ /* history store */ ])
        },
        mounted: function(){
            this.$watch("$data", function(n){
                this.track( JSON.parse(JSON.stringify(n)) ) // to remove watchers
            }, { deep: true, immediate: true});
        }
    })

Then, you can use something like recursive-diff to compare and generate diff between any two points in history or push the new object into something like object-history which will then manage the history for you.

Leave a comment