Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Model update and makeUpdate

$
0
0
If found strange behaviour of update (and destroy) operations after can.js update from 1.1 to 2.0. After update my model data become corrupted on the client, some attributes (nested maps) become empty (or default) after update, if they have defaults values (via attributes) plugin.

What I found out that this strange behaviour takes place due to new stuff like makeUpdate.

I send a request to server to update a model and say server responds with {createdAt: ..} data.

In can 1.1 
This data ({createdAt: ..}) will be passed to "updated" method and will update the instance with passed attributes (just adds createdAt attribute in this case).

In can 2.0.
We have a slightly different behaviour by default, because we now makeUpdate is defined as "model".
So after request model method is called and raw data {createdAt: ..} converted there to Model instance and then this instance is passed to "updated" method. There in "updated" method initial instance is merged with new model instance (created by model method). This causes different strange behaviors like replacing attributes with their default values

This behaviour can be fixed by setting makeUpdate to '' (empty string) on static properties of model class. But I wonder whether it is a bug or feature?

I'm not sure what was the intention behind introducing and defining makeUpdate and makeDestoy as "model" by default, but it seems to break things.

Viewing all articles
Browse latest Browse all 3491

Trending Articles