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

[BUGFIX DEPRECATE] fixes and deprecates when a user re-exports a model multiple places for use #4886

Closed
wants to merge 7 commits into from

Conversation

runspired
Copy link
Contributor

@runspired runspired commented Mar 22, 2017

@bmac If good this should be backported to release and beta.

This twiddle demonstrates the issue: https://ember-twiddle.com/035a072e1818f48c09ac9a38f13b1773?openFiles=twiddle.json%2C

All Ember versions prior to 2.12 work with all ED versions. Beginning in 2.12 (I think we fussed with double extend) this begins breaking in ED.

We can temporarily fix this with a deprecation by extending the class ourselves.

@runspired runspired changed the title warn when a user re-exports a model multiple places for use Error when a user re-exports a model multiple places for use Mar 22, 2017
Copy link
Member

@hjdivad hjdivad left a comment

Choose a reason for hiding this comment

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

Being able to re-export a class is a feature of ember data today. As we discussed oob, the factoryFor changes have broken this in subtle ways as you can get the wrong modelName on a re-exported model, which can get used to build URLs in adapters &c.

But we should be able to deal with this more gracefully for Ember Data users by deprecating with a double extend when we detect this has happened.

So, when we detect that a class already has a modelName we double extend and warn with a deprecation.

thoughts?

@runspired
Copy link
Contributor Author

I like the suggestion from @hjdivad. Since @stefanpenner is out, perhaps @krisselden or @rwjblue has thoughts on the best approach here?

@runspired runspired changed the title Error when a user re-exports a model multiple places for use [DEPRECATE] deprecate when a user re-exports a model multiple places for use Mar 23, 2017
@runspired
Copy link
Contributor Author

@hjdivad updated

@runspired runspired changed the title [DEPRECATE] deprecate when a user re-exports a model multiple places for use [BUGFIX DEPRECATE] deprecate when a user re-exports a model multiple places for use Mar 23, 2017
@runspired runspired changed the title [BUGFIX DEPRECATE] deprecate when a user re-exports a model multiple places for use [BUGFIX DEPRECATE] fixes and deprecates when a user re-exports a model multiple places for use Mar 23, 2017
`import Model from './${klass.modelName}';\n\n\texport default Model.extend();`;

if (hasFactoryFor) {
klass = factory.class = klass.extend();
Copy link
Member

Choose a reason for hiding this comment

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

It seems like a bug to me that ember allows setting factory.class like this...

Copy link
Contributor Author

@runspired runspired Mar 23, 2017

Choose a reason for hiding this comment

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

if it is, then I don't think we have a path forward other than to throw an error. Would be only slightly breaking.

Copy link
Contributor

Choose a reason for hiding this comment

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

factoryFor isn’t supposed to allow that, I thought we were using proxies to error in debug for that.

Copy link
Member

Choose a reason for hiding this comment

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

@krisselden - We do exactly that, for all other properties other than create and class. We should fix this (e.g. throw if class or create are attempted to be set).

Copy link
Member

Choose a reason for hiding this comment

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

@runspired - We could still do what you want I think. Either:

  • do the double extend when we detect modelName is not a match, register, then look up again for them...
  • create an cache our own "fake factory" here...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I prefer the register approach given it is "more correct" in terms of intent. Would be weird if ED and the registry were out of sync.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

@rwjblue / @krisselden i totally agree with you guys, the issue is ember-data's reliance on constructor.modelName. I have removed as much of this dependence as can (I believe) without public API change...

Copy link
Member

Choose a reason for hiding this comment

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

I believe if users have tests that pollute the constructor, they should subclass in the own tests. I don't believe we should subclass for them.

to continue allowing this ignores the case where modelName is set but is
the same.
*/
if (klass.modelName && klass.modelName !== modelName) {
Copy link
Member

Choose a reason for hiding this comment

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

In theory (for the test case), we could detect if the original container has been destroyed or changed and if so, just seamlessly transition without a warning?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ugh, I hadn't even considered tests mutating this yet. :'(

Thoughts on how would we differentiate between "modelName set by previous container" and "modelName set by previous location's lookup"?

Copy link
Member

@stefanpenner stefanpenner Apr 14, 2017

Choose a reason for hiding this comment

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

if the owner is different? Maybe we store an owner version.


  • I think tests should just double extend themselves (this is aligned with how the language works)
  • we should just explicitly not support (via warning or something) double re-exports of models until modelName goes away entirely. But not try to be clever about fixing?

@runspired runspired force-pushed the feat/warn-on-reexports branch from d6c2e07 to 586dba7 Compare April 29, 2017 21:15
@runspired
Copy link
Contributor Author

I believe this is what folks are hitting in #6143

@runspired runspired closed this Jan 22, 2020
@runspired runspired added 🏷️ cleanup This PR primarily removes deprecated functionality and removed Cleanup labels Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ cleanup This PR primarily removes deprecated functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants