vendredi 6 février 2015

Ember Data won't normalize (Assertion Failed: Expected an object as `data` in a call to `push`/`update`)

In my Ember app, I get notifications from a websocket. When the websocket receives a message (encoded as JSON), I want to push it into the store.


Here's my code so far:



console.log('About to normalize', data);
var normalizedData = this.store.normalize('message', data);
console.log('About to push', normalizedData);
this.store.push('message', data);


data and normalizedData end up being exactly the same values, which is something like this:



{"message":{"id":1,"chatroom":1,"player":1,"content":"A message"}}


And calling the push method provokes this error:



Error: Assertion Failed: Expected an object as `data` in a call to `push`/`update` for message ,
but was {"message":{"id":1,"chatroom":1,"player":1,"content":"31232132113"}}


I don't know what is wrong. When Ember gets a specific message from the server, it receives the same kind of JSON and Ember Data deals well with it. When it comes from a websocket and needs to be pushed, it crashes.





Aucun commentaire:

Enregistrer un commentaire