-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 Managed Adapters & Serializers #2617
Store Managed Adapters & Serializers #2617
Conversation
@@ -185,6 +185,8 @@ Store = Ember.Object.extend({ | |||
store: this | |||
}); | |||
this._pendingSave = []; | |||
this._adapterInstances = {}; |
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.
Object.create(null) seems appropriate for this
Thanks for the PR, left some comments |
Thanks for the comments @igorT. Didn't know about The addition of Having to:
For potentially 4 different serializer types is the justification - and then if you have I wasn't sure if it should be a function outside of the object (such as |
@@ -250,7 +252,8 @@ Store = Ember.Object.extend({ | |||
|
|||
if (DS.Adapter.detect(adapter)) { |
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.
@igorT @stefanpenner Do we still want passing a class 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.
I think so because we just looked it up couple lines above?
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.
This seems inconsistent to me. I mean, I thought we now should always lookup adapter/serializer via the container and not instanciating it. Also, we encourage strings everywhere, but in this case we still want to fully support a store definition with an adapter property a class ?
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.
Isn't the adapter here a result of the looked up string?
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.
hum, ok, I'm probably missing something, I thought the lookup returns an instance, not a class.
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.
Ah maybe you're right i thought you meant class vs a string
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.
Well, I think I'm just too bad explaining what I have in mind 😖
So I will try again.
Historically, the user can affect a class or a string to the adapter
property. As a result, there is this chain of checks. If the adapter
property is a string, then the adapter is looked up via the container, or if it's a class (actually a subclass of DS.Adapter), then it is instantiated here.
My question is: do we still want to allow the user define the adapter
property as a class ? It seems to me this would be inconsistent with the "string everywhere" paradigm.
Please, tell me it's clear now... or tell me to take an intensive English training course 😸
@sly7-7 (and others) in regards to removing I think if the order of lookup is/will change it might be an opportunity to simplify both the adapter and serializer lookup preferences.. Current preference/orderAdapters:1 Serializers:1 SimplifiedAdapters:
Which would result in: Serializers:
Which would result in: |
@jmurphyau apologies for not getting back to you sooner. Getting up to speed now after the holidays. Wouldn't the simplified order prevent people from having custom adapters for custom stores? |
Can you also please rebase/squash the PR? |
Awesome work btw @jmurphyau |
@igorT For a custom adapter on a custom store, this currently exists as item 3 in the current implementation:
and item 2 in what I've documented as a simplified preference/order:
Also, something worth noting that may not be completely obvious to everyone reading this PR - the "simplified preference/order" I've detailed in the comments above is not actually implemented in this PR - this PR is only about allowing multiple stores to work with the embedded record mixin. Should I split out the preference/order discussion into something/somewhere else? If so, where is appropriate? |
I think I've rebased this incorrectly - I'm not 100% sure?? Sorry guys don't really have much experience with Git.. I'll investigate see if I've fucked it up/need to change it.. |
Can you try |
45d9c6e
to
3e424a4
Compare
Done - that looks much better. Thanks @igorT. I think using GitHub for Mac may have caused part of the problem |
@@ -38,7 +38,7 @@ test("the deprecated serializer:_default is resolved as serializer:default", fun | |||
deprecated = container.lookup('serializer:_default'); | |||
}); | |||
|
|||
ok(deprecated === valid, "they should resolve to the same thing"); | |||
ok(deprecated.constructor === valid.constructor, "they should resolve to the same thing"); |
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.
Can you add a test that assert your config for singleton:false
ping @jmurphyau |
@bmac - I must have missed the last few comments from you. I'll split out those tests & add the tests you mentioned over the next day or so. |
@bmac - I've split the tests out - please review. |
b362922
to
ed0690c
Compare
ed0690c
to
943d891
Compare
@@ -185,6 +185,7 @@ Store = Ember.Object.extend({ | |||
store: this | |||
}); | |||
this._pendingSave = []; | |||
this._containerCache = Ember.create(null); |
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.
why do we need a cache?
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.
It's where the store holds its Serializers and Adapters instances - since each is now one instance per store rather than a singleton.
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.
ah ok
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.
on destroy, we should be sure to also destroy these. So they can do needed cleanup
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.
Ok cool - I'll get onto that
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.
👍
Adapters and Serializers are now store managed - with each store instance holding a unique instance of each serializer and adapter. They are no longer singletons. This allows multiple stores to be used with ember-data.
943d891
to
09f4fae
Compare
09f4fae
to
9fcf261
Compare
@stefanpenner - I've made the changes discussed and a few additional ones since the serializerForAdapter function has moved. |
4587ce1
to
781c48b
Compare
These calls are not required here.
Since multiple store tests are now their own file and the secondary stores are created in setup() there’s no need to create secondary stores in this test
Thanks for the awesome work! We rebased it and merged it, but kept you as an author. Thanks! |
Thanks everyone for all you help & feedback with this PR - it was my first PR ever. Was a good experience and I've since learnt a lot about Git and GitHub and moved away from GitHub for Mac in favour of the command line - so shouldn't have any issues with rebase again :) I've created two other PRs that have stemmed from this PR #2918 Remove serializerForAdapterThis has stemmed from @bmac's issue #2916 in relation to keeping things consistent. #2919 Serializer & Adapter Lookups Preference/OrderThis has stemmed from the above discussion started by @sly7-7 around the lookup order of serializers and adapters. Parts of the discussion are hidden behind outdated diffs (e.g. it started in 'sly7-7 commented on an outdated diff on Dec 20, 2014') Serializer and adapter order/preference was discussed above but nothing really appeared to be decided - so I've started with a base - something to go off - which I hope gets things moving in this regard. |
Pull request to make a store instance responsible for it's own adapter and serializer instances - as suggested fix to #2588 by @tomdale.
Serializers and Adapters are no longer singletons.
Failing test included.