teddyzeenny / ember-data-factory

92 stars 8 forks source link

Add a store-centric API #6

Open lukemelia opened 10 years ago

lukemelia commented 10 years ago

I would like to see an API more conducive to unit tests, that does not require an app object to be passed to create or build. Instead, a store could be passed, which is the only thing app is used for except for the Ember Testing helpers. What do you think?

teddyzeenny commented 10 years ago

Sounds good. To be honest when I wrote this I didn't have unit tests in mind. I use it for end-to-end tests (even with the backend by using the rest adapter instead of fixture), and I never use it without the Ember Testing helpers.

That said, I don't see any harm in switching to store and giving more focus to isolated tests.

teddyzeenny commented 10 years ago

So I started looking into this. There's one problem, if you currently define a property to be a function, the first argument passed is the app:

Factory.define('post', {
  title: 'Post Title',
  author: function(app) {
    // the first argument passed is the app (same as ember-testing helpers)
    return app.__container__.lookup('user:main');
  }
};

I don't mind doing a breaking change, but the problem is how would one access the app otherwise (assuming window.App should soon become deprecated)