These are chat archives for canjs/canjs

6th
Apr 2017
Szabolcs Schmidt
@sszabolcs
Apr 06 2017 13:49

Hi!

Is there a way to reload a CanJS 2 can.Model? Let's say I have a model, I change an attribute on it and then save it. During the save the backend also modifies another attribute based on a business logic. I would like to know about this change on the client side. I will already know about the change which I made on the client side but not on the other change which was made by the backend.

Gregg Roemhildt
@roemhildtg
Apr 06 2017 14:34

@sszabolcs I force a reload on canjs models sometimes. I have my view model, like this:

    objectsRefreshCount: {
        value: 0,
        type: 'number'
    },
    objectsPromise: {
        get () {
            this.get('objectsRefreshCount');
            const params = this.parameters ? this.parameters.serialize() : {};
            const promise = this.view.connection.getList(params);

            return promise;
        }
    },

I'm using can-connect but it should work the same. Whenever I need to refresh the data, I just call this.objectsRefreshCount ++;

Szabolcs Schmidt
@sszabolcs
Apr 06 2017 14:38
@roemhildtg Thanks, I'll try to experiment with your code.
Gregg Roemhildt
@roemhildtg
Apr 06 2017 14:39
You'll have to tweak it a bit for canjs 2, since I'm using 3
Szabolcs Schmidt
@sszabolcs
Apr 06 2017 14:48
Of course!