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

Add adapter to module for model #34

Merged
merged 4 commits into from
Apr 11, 2014
Merged

Add adapter to module for model #34

merged 4 commits into from
Apr 11, 2014

Conversation

mixonic
Copy link
Sponsor Member

@mixonic mixonic commented Apr 10, 2014

See emberjs/data#1859 for some context.

moduleForModel is kinda lame. It limits you to the fixture adapter, which many of the more experienced Ember devs would not recommend, but we still tell people it is awesome and they should check it out.

This makes it a bit better. With DS._setupContainer in Ember-Data, moduleForModel will be able to setup an isolated container to have all of Ember-Data. You can again use RESTAdapter and custom adapters without jumping through more hoops than you already do for model relations.

var App = Ember.Application.create();
App.ApplicationAdapter = DS.RESTAdapter.extend();
App.Whap = DS.Model.extend({ nut: DS.attr('number') });

moduleForModel('whap', {
  needs: ['adapter:application'],
  setup: function(){ fakehr.start() },
  teardown: function(){ fakehr.reset() }
});
test('saves to ajax', function(){
  var whap = this.subject();
  whap.set('nut', 5);
  // with expect from https://github.com/trek/fakehr/pull/6
  fakehr.expect('post', '/whaps').respond(
    200, {'Content-Type': 'application/javascript'}, '{"id": "3e23", "nut": 5}');
  return whap.save().then(function(){
    ok(true, 'TRUUUEEEE!!!');
  });
});

Welcome to your brave new fixture-adapter-less future. For pre-DS._setupContainer users, behavior is unchanged. Fixture adapter is still default if you do not inject an application adapter yourself.


if (DS._setupContainer) {

}
Copy link
Member

Choose a reason for hiding this comment

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

I think this can be minimized to:

😉

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

If your comments don't involve lederhosen I don't want to read them.

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

Fixed. Gracias sir.

Copy link
Member

Choose a reason for hiding this comment

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

I hope this is sufficient, crazy man:

holaradio

Also, I'll try harder next time.

@stefanpenner
Copy link
Member

LGTM will merge tonight

In emberjs/data#1859 DS._setupContainer was
introduced to Ember-Data. This allows moduleForModel to use an
isolatedContainer with all the trimmings of Ember-Data instead of only
the store, including default serializers and adapters.

Example usage might read like:

    var App = Ember.Application.create();
    App.ApplicationAdapter = DS.RESTAdapter.extend();
    App.WhapModel = DS.Model.extend();

    moduleForModel('whap', { needs: ['adapter:application'] });

Ember-Data will now discover the application adapter with its regular
application semantics.

In Ember-Data installations pre-DS._setupContainer, the old behaviors
(for better or worse, mostly worse) are unchanged.

whoops
@mixonic
Copy link
Sponsor Member Author

mixonic commented Apr 10, 2014

If you want to try this you can now build Ember-Data master (thx @stefanpenner) or use the builds linked to in emberjs/data#1859

stefanpenner added a commit that referenced this pull request Apr 11, 2014
@stefanpenner stefanpenner merged commit 15a976a into emberjs:master Apr 11, 2014
@stefanpenner
Copy link
Member

👍

@mixonic mixonic deleted the add-adapter-to-module-for-model branch April 11, 2014 13:04
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

Successfully merging this pull request may close these issues.

4 participants