-
-
Notifications
You must be signed in to change notification settings - Fork 408
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
Deprecate Implicit Injection on arbitrary Ember Framework objects #680
Deprecate Implicit Injection on arbitrary Ember Framework objects #680
Conversation
1bb386f
to
c0f434a
Compare
c0f434a
to
cf461b2
Compare
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.
Thanks for taking this on @snewcomer! I'm very much in favor!
@@ -0,0 +1,127 @@ | |||
- Start Date: 2020-10-04 | |||
- Relevant Team(s): Ember.js | |||
- RFC PR: (after opening the RFC PR, update this with a link to it and update the file name) |
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 update with the PR link?
Removing implicit injections is not possible until we first issue deprecations. | ||
This helps us maintain our strict semver commitment to not completing a major version bump and | ||
removing APIs without a deprecation path. As a result, it will take us 3 phases to remove `owner.inject`. |
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 we need to explain a bit more about why we need multiple phases here (and in each phase).
At the summary level, we should explain that it is impossible for ember-data
to remove its owner.inject
calls without being a breaking change (that could not have issued a deprecation for, since we couldn't tell if you actually used it).
This helps us maintain our strict semver commitment to not completing a major version bump and | ||
removing APIs without a deprecation path. As a result, it will take us 3 phases to remove `owner.inject`. | ||
|
||
### 1. Deprecate implicit injection on target object |
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.
Should mention why we deprecate this first, and how you avoid the deprecation. Specifically, this would allow users to add @service store;
explicitly as a way to prevent the deprecation and avoid relying on the implicit injection.
and setter on the target. Whenever the property is accessed, we will check if the property is explicitly injected. If it isn't, | ||
we will issue a deprecation with an until value, id and url to read more about this deprecation. | ||
|
||
### 2. Deprecate `owner.inject` |
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.
Should mention how folks (like ember-data) should mitigate this deprecation. One possible answer is that ember-data can't remove its owner.inject
until after ember-data@4. This ordering is a bit nebulous at the moment...
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.
FTR we eagerly inject only because of defaultStore. Were defaultStore not present we would deprecate this ourselves. Deprecating implicit injection without deprecating defaultStore is surprising to me, I'm hoping there was a follow up RFC merged that I've missed 😅
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 haven't seen DS.defaultStore
anywhere for quite a while. Does it still exist?
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.
@snewcomer it's not an EmberData concept, it's an Ember concept. You even linked my issue for needing the framework to remove it in the RFC but I think you possibly misunderstood it as something that we (EmberData) needed to remove. It is currently located here in Ember's codebase: https://github.com/emberjs/ember.js/blob/master/packages/%40ember/-internals/routing/lib/system/route.ts#L2323
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.
@runspired is I believe referring to this computed property: https://github.com/emberjs/ember.js/blob/master/packages/@ember/-internals/routing/lib/system/route.ts#L2319
We can and should also deprecate that property, though I think it will have to be for the 5.0 cycle. The deprecation warning should be enough to let user's know that they are using the deprecated functionality, and should explicitly inject @store
, I think.
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.
@pzuraq the issue is that if we don't eagerly inject ourself the find
call will not be the same as having called ember-data's
store.find
and results in either this assert triggering or (for folks that happen to have a find
method on their model) a very confusing and unexpected request triggering.
assert(
`${classify(name)} has no method \`find\`.`,
typeof modelClass.find === 'function'
);
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.
For folks that were previously making use of EmberData's injected store, they will get the deprecation and hopefully convert to using explicit service injection. For new apps in 4.0 and for places where devs simply forget to add in the explicit inject though the confusion will remain.
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.
Right, exactly. I don't think this will be a huge issue as long as we add a deprecation that says loudly in the console:
You are using the deprecated
store
computed property. This computed property is not a service, and it has confusing and usually unexpected behavior. If you are using Ember Data or another addon that provides astore
service, you should add@service('store')
to your route in order to get access to the store service instead.
I do agree ideally that the deprecation should be sooner rather than later ideally, but we'll have to see where it fits in the timeline.
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.
When deprecating default store we should deprecate implicit record loading in default model
hook as well. There is a open RFC to do so #557.
It is important to consider the timeline of these three phases. Many addons and apps will need to make minor and major | ||
changes to their codebase. We need to consider this as we move through each phase. |
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 agree that considering the phases is important, can you update to indicate relative timing (and likely "triggers")? As it stands now, we say that the timing is super important but don't actually say what the timing is or should be 😆
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 a side note, I may be wrong here because of some misunderstanding or sth.
But I remember that there used to be some feature (that i have never relied on) where an implicit route would automagically load a model, is this a thing or is this something i just made up?
The question is, if it exists, how its going to be deprecated?
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.
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.
Looks like it is it, thank you @snewcomer.
Was wondering how these behaviors play out in this RFC
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.
As for the triggers, how does this sound?
- Introduce deprecation on target
- Next release introduce deprecation on owner.inject
- Simmer until v4?
|
||
## Open Questions | ||
|
||
- Should we simply replace the [docs](https://guides.emberjs.com/release/applications/dependency-injection/#toc_factory-injections) on Factory Injections without an alternative? |
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.
IMHO, yes.
Co-authored-by: Robert Jackson <[email protected]>
Co-authored-by: Robert Jackson <[email protected]>
I misplaced my comment, so I'll quote it here.
|
Co-authored-by: Richard Viney <[email protected]>
Co-authored-by: Bert De Block <[email protected]>
One use case I have that does not seem easy to migrate is to inject a service that registers global route events to |
Not sure if I fully got it. But can't it be done using |
@jelhan I forgot to mention the use case if for an addon to provide a service that is aware of global router states. The service from the addon does use |
Still not getting why you would need to inject the service in application route. Couldn't you call a setup method of the service in instance initializer directly? |
@xg-wang I’m not sure that this particular deprecation would affect that, because it should still be possible to lookup services with If not, can you add some code examples of the case you’re concerned about in order to clarify? |
@xg-wang - Maybe throw together a demo repo for us? I'm also unsure that this RFC directly affects your scenario, but without understanding the scenario better I can't be sure... |
@jelhan @pzuraq @rwjblue apology for the late response. I created https://github.com/xg-wang/test--router-injection-addon to explain what I meant. The addon will need to prepare initial states, I have a Being injected into the main route, the service gets access to all application route transitions. I hope the demo makes sense, or I can explain more. It's totally possible I was doing things hacky and silly here, please let me know if there's a better way for the use case. |
Talked to @pzuraq offline, the recommendation for this timing requirement in my demo addon is to look up the service in an |
We discussed this at todays team meeting, and are moving into final comment period. |
Rendered
close #508