Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

store.push(type, data) deprecated - WHY? #3402

Closed
danshapir opened this issue Jun 21, 2015 · 6 comments
Closed

store.push(type, data) deprecated - WHY? #3402

danshapir opened this issue Jun 21, 2015 · 6 comments

Comments

@danshapir
Copy link

This is the best way to insert data into the store and it has been killed in favor of JSON API objects. But if my API is a JSON API I would use the Adapter as is, we have an API that requires custom ajax call and then we inject the data into the store through the push method. Killing it will basically kill our entire application!

I would like to be able to push data that is a JSON that looks just like the model.
For example:

user/model.js
export default DS.Model.extend({
  userName: DS.attr('string'),
  password: DS.attr('string'),
  extendedData: DS.attr('string'),
  firstName: DS.attr('string'),
  lastName: DS.attr('string'),
  localCurrency: DS.attr('string'),
  rAFLink: DS.attr('string'),
  mobileSessionToken: DS.attr('string'),
  email: DS.attr('string'),
  oRNLink: DS.attr('string'),
  isAuth: DS.attr('boolean', {defaultValue: false})
});

Will work with:

store.push('user', { userName: 'myUserName', firstName: 'Dan', lastName: 'LastMe' .....} );
@wecc
Copy link
Contributor

wecc commented Jun 21, 2015

We're not killing store.push but changing the internal ED format to match JSON-API format and as a result we're also removing the first argument due to the nature of JSON-API and the requirement of types within the payload. store.push(data) is the new store.push.

store.push has always required a normalized format, usually referred to as the "internal ED format" but if your API payload already looks like the internal ED format you could skip the normalizing step and just give store.push your raw payload.

If you're using the built-in JSONSerializer (or RESTSerializer for that matter) you should be able to use store.normalize to convert your API payload to the new internal ED format and then pass that to store.push:

store.push(store.normalize('user', { userName: 'myUserName', firstName: 'Dan', lastName: 'LastMe' .....}));

If you manually extend one of the built-in serializers you have to opt into the new Serializer API to have them normalize to JSON-API.

@danshapir
Copy link
Author

I'm always normalizing my data:

store.push('user', store.normalize('user', { DATA });

You are saying that just:

store.push(store.normalize('user', { DATA });

Will work? If so some major changes have been made to the normalize function.

@wecc
Copy link
Contributor

wecc commented Jun 21, 2015

The built-in serializers have been updated so their normalize functions return JSON-API if you're using the new Serializer API.

@danshapir
Copy link
Author

How do I use the new Serializer API and what happens if I dont use it?

BTW,
Thanks you so much for your answers!

@wecc
Copy link
Contributor

wecc commented Jun 21, 2015

If you don't extend the built-in serializers but rely on the default ones they will opt in automatically for you.

If you extend any of the built-in serializers you can opt into the new Serializer API by setting isNewSerializerAPI: true when extending. A transition guide is on it's way that will explain what additional actions are required.

If you use the new JSONAPIAdapter/JSONAPISerializer they will always use the new Serializer API.

You should upgrade to the new Serializer API as it will be mandatory in Ember Data 2.0. You don't have to update in Ember Data 1.13 but it's highly recommended.

Feel free to ping me on the Ember Community Slack, I'd be happy to help you get this sorted.

@danshapir
Copy link
Author

You are huge, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants