-
-
Notifications
You must be signed in to change notification settings - Fork 130
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 support for custom dataStore - Closes #209 #210
Conversation
Now you can use a custom dataStore other than the default dataStore. ```js export default Ember.Route.extend(InfinityRoute, { customStore: Ember.inject.service('my-custom-store'), model(params) { return this.infinityModel('product', { perPage: 12, startingPage: 1, store: 'customStore' }) } }); ```
@hhff I guess I broke something, huh? I don't really understand how these tests work. Can you take a look at this? |
Thanks @Redsandro ! Do the tests run locally for you? |
@hhff yes**, but I don't understand why the Travis tests fail. They say "The command "ember try $EMBER_TRY_SCENARIO test" exited with 1." before PhantomJS is even started. **) All 76 tests run fine up to EmberJS 2.8. From 2.12, I'm starting to see errors that are irrelevant to my PR. I think.
For errors e.g. test 42, 43 and 44 on Ember 2.12:
Funny detail is that the error messages for the fails are doing what the test description sais. Perhaps the test is wrong, because the error is actually what is desired. On Ember Beta half of the tests fail. But again, I think not relevant to this PR. I didn't touch css or selector functionality. Merely inserted option for datastore. I'm already using it. 😃 |
Got it - ok! Would you try updating node version in the |
@hhff ah yes that's better. Now travis sees the same results as I. |
Thanks @Redsandro - those final tests may be an issue with the state of Ember's release cycle. I've seen that happen a couple times. Will look into it! |
This looks like a great PR! Looks like some of the tests are failing - same issue here: emberjs/ember-qunit#256 @hhff Any thoughts on next steps to getting these tests passing? |
@Redsandro - can you please merge master, and ping @snewcomer when you're done? We've just fixed up all the testing weirdness 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Redsandro @hhff Here are some thoughts on this PR! Let me know what you think.
Last idea would be to get some sort of test w/ a custom store. If you need help with this, I can give it a shot.
addon/mixins/route.js
Outdated
@@ -151,7 +159,7 @@ const RouteMixin = Ember.Mixin.create({ | |||
throw new Ember.Error("Ember Infinity: You are using an unsupported version of Ember Data. Please upgrade to at least 1.13.4 or downgrade to 1.0.0-beta.19.2"); | |||
} | |||
|
|||
if (Ember.isEmpty(this.get('store')) || Ember.isEmpty(this.get('store')[this._storeFindMethod])){ | |||
if (Ember.isEmpty(this._store) || Ember.isEmpty(this._store[this._storeFindMethod])){ | |||
throw new Ember.Error("Ember Infinity: Ember Data store is not available to infinityModel"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Redsandro could we potentially change this assertion to Store is not available...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that would be goldplating it. I assume one that creates and specifies a custom store knows what they're doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PS - I think I misunderstood your comment. 😊 You just want to change the error message. I leave that to you. Need to catch some 💤 before busy week starts!
addon/mixins/route.js
Outdated
const perPage = options.perPage || this.get('_perPage'); | ||
const store = options.store && this.get(options.store) || this.get('store'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably need to assert that options.store
is a string in order to do this.get
. If they pass an object or something, it might blow up on them!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed.
addon/mixins/route.js
Outdated
@@ -193,6 +199,7 @@ const RouteMixin = Ember.Mixin.create({ | |||
currentPage: startingPage, | |||
_firstPageLoaded: false, | |||
_perPage: perPage, | |||
_store: store, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Redsandro We also probably need to be able to customize the _storeFindMethod
method. What are your thoughts on this? Does your custom store use the same query
method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also need to make sure that their method returns a promise as well. here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are your thoughts on this? Does your custom store use the same query method?
My thoughts are that a custom store, just like a custom route or component, extends the Ember default (in this case Store) and as such is supposed to implement the same behavior as Ember.DS.
I don't see a use case where one would want to customuze the _storeFindMethod
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Redsandro So here is one example. https://github.com/toranb/ember-cli-simple-store
I have created a custom functional store in the past and I have find/findAll methods that wouldn't work with this. Both of these just use plain Ember objects / JS objects as an identity map just like ED does (but muuuuuch simpler).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I have never used a store that wasn't just Ember DS extended. Indeed this functionality is something that someone might want. But I'd consider using non-Ember-DS datastore with nondefault query mechanisms a separate PR/feature (request) once this is in.
|
@snewcomer said:
I don't understand how the store works in tests, and I have no clue how that would work with a custom store. Writing a custom store in an Ember app is as simple as:
import DS from 'ember-data';
export default DS.Store.extend({}); However, you probably want a custom store to have a different adapter and/or serializer than the default store.
service: import DS from 'ember-data';
export default DS.Store.extend({
adapterFor() {
return this._super('custom-store');
},
serializerFor() {
return this._super('custom-store');
}
}); You must then inject the store to your route before the infinityModel can use it: export default Ember.Route.extend(InfinityRoute, {
customStore: Ember.inject.service('custom-store'),
model(params) {
return this.infinityModel('product', { perPage: 12, startingPage: 1, store: 'customStore' })
}
}); |
Oh great I broke it. |
I have added a check for the string type. As I am currently on a time deficit, I would propose that this is safe to merge as is, and you can take a stab at writing a test. |
@Redsandro Awesome. Thanks for putting in the hard work! Yep I see where the disconnect is :). So yeah I was hoping this PR could handle both a custom store like you defined, but also any service (w/ a local cached array of JS objects) that wishes to request data from a backend and update that cache...not just ED specific. But now seeing that may be out of scope for this PR and I can tackle in a separate PR. |
@snewcomer very well! 👍 |
@Redsandro Could you either:
Your call! |
@snewcomer sorry for the delay. I keep forgetting Github doesn't automatically add the owners of the original repo as collaborators to the fork. I've invited you manually. I'm sorry I haven't been more accomodating in tailoring this PR. I'm very thankful you're taking the time to merge this properly. If you haven't been notified by email, let me know and I will send you the invitation link. |
@Redsandro Here are some small minor changes for your review, branched off of your |
As you probably already know, Super happy you put in this PR! 👍 |
small improvements. Review and merge into your branch if you would like
@snewcomer Looking good. I couldn't follow the concequences of the changes by thought-simulation alone so I waited until I had the time to try this PR in an app with full custom store using dependency |
@hhff for your review. |
Awesome - thankyou so much @Redsandro & @snewcomer ! |
@hhff It seems it is merged to master but not released at latest |
Hi @tradziej - @snewcomer is in the process of working on the 1.0 release of Ember Infinity, and the master branch is in a state of development for now, so we're holding off new releases for that reason. I agree it's confusing and we're getting close to a beta version - for now if that's a feature you need, please use the git tag for that feature merge in your package.json - |
@tradziej yeah hopefully sometime next week we can release a new version! |
Now you can use a custom dataStore other than the default dataStore.
Closes #209