Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Conversation

@alexlafroscia
Copy link
Collaborator

@alexlafroscia alexlafroscia commented Jun 1, 2016

@taras and I worked on this PR together, to introduce a mixin that can be added to an Ember Data adapter. This should be seen as a first step toward solving #85.

When included, the mixin will use the ajax service for networking, instead of the code provided as part of the RestAdapter. Since the ember-ajax code was based on the code that it is now replacing, bridging the gap here was pretty straightforward.

The one thing that I'm not sure about right now is the naming of file that the mixin is found in. I think having it simply called ajax-support is a little ambigious, especially when the implementation file is called ajax-request. They're just a little too similar. I'd love suggestions on a better name.

@taras
Copy link
Contributor

taras commented Jun 1, 2016

This looks great. We need to describe the migration path for people who're looking to adopt this. It can serve as a transition path towards using Ember Ajax with Ember Data. Primarily, we need to show how error handling needs to be adjusted to work with Ember Ajax in Ember Data.

On that note, we'll need to add Ember Data Error object detection to our error detection helpers.

@alexlafroscia
Copy link
Collaborator Author

alexlafroscia commented Jun 1, 2016

Yeah, agreed. Definitely need to add some docs, but I'd rather not just add more to the README... There's a lot of information in there already. Maybe usage example in the mixin file? I can add some of that.

What's the right way to add detection of the Ember Data errors? We'd need to import the errors and then do an instanceof check, so Ember Data would become an Ember Ajax dependency?

@taras
Copy link
Contributor

taras commented Jun 1, 2016

What do you think about moving the mixin to /adapters/ajax-support-mixin.js and creating a README.md file there with this information.

@alexlafroscia
Copy link
Collaborator Author

I think that's kind of confusing, having a mixin in the adapters directory. It feels like straying from the convention without a strong reason.

@taras
Copy link
Contributor

taras commented Jun 2, 2016

That's kinda how Ember Data does it, Not exactly, but similar https://github.com/emberjs/data/blob/master/addon/-private/adapters/build-url-mixin.js

@alexlafroscia
Copy link
Collaborator Author

I see what you're saying... But that's also a "private" module, not public. To me, addons have a given structure and I think adhering to the convention is a better way to go.

@taras
Copy link
Contributor

taras commented Jun 2, 2016

@alexlafroscia ok, what do you think about putting the upgrade instructions into the README for now and later we can give it a section on a documentation site.

@taras
Copy link
Contributor

taras commented Jun 3, 2016

What's the right way to add detection of the Ember Data errors? We'd need to import the errors and then do an instanceof check, so Ember Data would become an Ember Ajax dependency?

@alexlafroscia that's a great point. I'll think about this today and get back to you.

@alexlafroscia
Copy link
Collaborator Author

I'm wondering if it's really necessary to add the ED error checkers... I mean, if they're opting into using the Ember AJAX mixin, they need our error checkers for network errors. If the ED networking code isn't being run, how do those errors crop up?

@taras
Copy link
Contributor

taras commented Jun 5, 2016

Yeah, you're right. Wi this strategy, it's not necessary because the assumption is that we will be running all of the Ajax code through Ember Ajax with the mixin. We should make this available as beta and have people try it.

@alexlafroscia
Copy link
Collaborator Author

Cool. I'll add a commit with some docs and we can cut a release with this. Would you want to include this as part of 3.0-beta.1? Or 2.5?

@taras
Copy link
Contributor

taras commented Jun 5, 2016

Let's stick within 2.x series for now. So, 2.5-beta.1?

@alexlafroscia
Copy link
Collaborator Author

@taras Can I get one last check-over before pulling this?


host: alias('ajaxService.host'),

namespace: alias('ajaxService.host'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should alias namespace, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find, thanks!

@alexlafroscia
Copy link
Collaborator Author

@taras can I get one last once-over on this before merging? I fixed that thing you caught.

README.md Outdated
const { JSONAPIAdapter } = DS;

export default JSONAPIAdapter.extend(AjaxServiceSupport, {
ajaxService: service('ajax'),
Copy link
Contributor

@taras taras Jun 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mixin does this, we don't need this line and we need to move `namespace: 'api'`` to the service. Right?

Copy link
Collaborator Author

@alexlafroscia alexlafroscia Jun 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RE: the ajaxService line, I know we don't need it. I just wanted to illustrate that you can specify the service to use, but maybe that was confusing? What do you think @taras?


RE: the namespace line, I wanted to show how you can specify certain things on the adapter. Otherwise, the whole adapter is just

export default JSONAPIAdapter.extend(AjaxServiceSupport);

which isn't much to show, really... Although maybe that's okay? What do you think?

Copy link
Contributor

@taras taras Jun 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that's fine. We want to show people that they can allow ember-ajax to take care of everything related to the request.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I'll update the example code to show a "minimal" example, and also include an "extended" one that's similar to what I originally put. Sounds good?

@taras
Copy link
Contributor

taras commented Jun 10, 2016

Other than the 1 comment, it's good to go.

@alexlafroscia alexlafroscia merged commit d8b1c29 into ember-cli:master Jun 17, 2016
@alexlafroscia alexlafroscia deleted the ember-data-mixin branch June 17, 2016 16:25
@dwickern
Copy link

dwickern commented Aug 4, 2016

This appears to add the namespace twice: first in the ember-data adapter and again in the ember-ajax service.

@alexlafroscia
Copy link
Collaborator Author

@dwickern can you make a new big ticket with some more information?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants