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

remove passing factories to store methods #3074

Merged
merged 7 commits into from
Jun 3, 2015

Conversation

fivetanley
Copy link
Member

Previously, we allowed users to either pass factories (subclasses of
DS.Model), or a string to store methods. For more consistency in the
container-based world where things are looked up through strings,
support for looking up via passing a factory has been removed.

This is part of a refactor that will remove state (like the store)
from Ember Data's factories in order to remove
Ember.MODEL_FACTORY_INJECTIONS.

@fivetanley fivetanley force-pushed the remove-passing-factories-to-store-methods branch 2 times, most recently from cff8ce5 to 3aea06b Compare May 16, 2015 18:36
@fivetanley
Copy link
Member Author

closes #3072

@fivetanley fivetanley force-pushed the remove-passing-factories-to-store-methods branch 3 times, most recently from 8f443a0 to 7271cf1 Compare May 16, 2015 20:41
@igorT
Copy link
Member

igorT commented May 17, 2015

I really wish I waited a day before rebasing references, this has been a source of major pain. ❤️ ❤️ Awesome work!


var adapter = this.lookupAdapter(type.modelName) || this.lookupAdapter('application');
adapterFor: function(modelName) {
Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string');
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 we might want to deprecate here if our own code was doing it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I fixed the places our own code was doing it.. Seems odd to ship a version that triggers deprecation warnings?

Copy link
Member

Choose a reason for hiding this comment

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

I am saying we should fix our own code as well, yes, but if we were doing it, seems like other people could've as well, and it would be nicer not to break their apps.

Copy link
Member Author

Choose a reason for hiding this comment

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

Their apps would be broken by everything else asserting anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

The fix is also pretty easy for others to incorporate.

@fivetanley fivetanley force-pushed the remove-passing-factories-to-store-methods branch 4 times, most recently from 93082ee to 9c9420f Compare May 22, 2015 05:13
@fivetanley
Copy link
Member Author

before the merge of #3075 :

2f8024b...b213ce1

You can look at the diff in #3075 for removing the store from factories.

// TODO: Ask Teddy what we should do here.
// Ideally this should always get passed a string.

var modelName = typeof modelNameOrFactory === 'string' ? modelNameOrFactory : modelNameOrFactory.modelName;
Copy link
Member

Choose a reason for hiding this comment

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

maybe deprecate?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think this gives users actionable feedback as it's in the debug adapter for the Ember Inspector. They probably won't build their own source and fix the deprecation warning. We try to avoid deprecations for code that isn't the user's.

@stefanpenner
Copy link
Member

SGB

@igorT
Copy link
Member

igorT commented May 24, 2015

Seems great except for the passing of the store to inverseFor

Stanley Stuart added 2 commits May 29, 2015 13:52
Previously, we allowed users to either pass factories (subclasses of
DS.Model), or a string to store methods. For more consistency in the
container-based world where things are looked up through strings,
support for looking up via passing a factory has been removed.

This is part of a refactor that will remove state (like the store)
from Ember Data's factories in order to remove
Ember.MODEL_FACTORY_INJECTIONS.
When using multiple stores with Ember Data, we want to avoid storing the
state on the factory itself. Because multiple stores currently share the
same factory, this means that the first store to look up the factory
will store itself as the `store` on that factory. That means that any
stores thereafter will receive factories whose `store` property
references the first store, not their own.
@fivetanley fivetanley force-pushed the remove-passing-factories-to-store-methods branch from 3f1a33e to 05ba8f8 Compare May 29, 2015 18:53
throw new Ember.Error("No model was found for '" + modelName + "'");
}
factory.modelName = factory.modelName || normalizeModelName(modelName);
factory.__container__ = factory.__container__ || container;
Copy link
Member

Choose a reason for hiding this comment

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

I am very suspicious of this. Seems like it would break for multiple app runs server side. cc @stefanpenner

Copy link
Member

Choose a reason for hiding this comment

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

Static methods just can't return concrete references to other factories. This doesn't appear to be used internally at all:

The following could be made to work: typeForRelationship(typeString, store) but not the single arg form.

The question is, as the rest of the system understands strings, why does this need to return a concrete reference in the first place.

Copy link
Member

Choose a reason for hiding this comment

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

Although this may appear drastic, this appears like the last lynch-pin preventing ED from being a good citizen in this area.

Copy link
Member

Choose a reason for hiding this comment

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

We need a factory in order to be able to reflect on it. To say if I am a user and I have message, does that message have any relationships that point to a user

Copy link
Member

Choose a reason for hiding this comment

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

Can you show me that code? Or provide an expanded scenario by which i can continue to think about this?

Copy link
Member

Choose a reason for hiding this comment

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

in slack we discussed this further. I provided the following example:

As nothing prevents two apps from having two different set of resolvers, factory level reflection without polluting instance state isn't really available to us.

The solution is to continue to purge instance state (the container/ store etc) from factories, and instead enable the needing wiring when instance information is present.

@fivetanley fivetanley force-pushed the remove-passing-factories-to-store-methods branch from 05ba8f8 to bcefa52 Compare June 3, 2015 00:11
@fivetanley fivetanley force-pushed the remove-passing-factories-to-store-methods branch from 4f621da to c3197d6 Compare June 3, 2015 15:28
fivetanley added a commit that referenced this pull request Jun 3, 2015
…re-methods

remove passing factories to store methods
@fivetanley fivetanley merged commit 3d0aeb3 into master Jun 3, 2015
@fivetanley
Copy link
Member Author

🎉

@bmac
Copy link
Member

bmac commented Jun 3, 2015

👯

@bmac bmac deleted the remove-passing-factories-to-store-methods branch September 24, 2015 21:27
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.

None yet

4 participants