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

Updated how we describe injecting Ember Data store #1541

Merged
merged 3 commits into from
Oct 16, 2020
Merged

Updated how we describe injecting Ember Data store #1541

merged 3 commits into from
Oct 16, 2020

Conversation

ijlee2
Copy link
Member

@ijlee2 ijlee2 commented Sep 25, 2020

Description

Through a Discord conversation, I realized that we didn't explain well when a developer needs to inject the Ember Data store service:

Developer: Hello all. Just a quick Q: I’m using this.store in my model() without injecting it as a service and it’s all working as expected. Am I missing something or am I just lucky? (I’ve just seen that the docs inject as a service)

I also noticed that the Zoey says has a Markdown typo (we unfortunately have to manually provide a <code> tag).

How to Review

I recommend reviewing commits one by one. Each commit makes the same type of change across different versions, starting with Ember 3.15 (Octane).

References

@@ -125,20 +125,18 @@ identifier, instead):
Ember Data is a powerful (but optional) library included by default in new Ember apps.
In the next example, we will use Ember Data's [`findAll`](https://api.emberjs.com/ember-data/release/classes/Store/methods/findAll?anchor=findAll) method, which returns a Promise, and resolves with an array of [Ember Data records](../../models/).

_Note that Ember Data also has a feature called a [`Model`](https://api.emberjs.com/ember-data/release/classes/Model), but it's a separate concept from a route's [`model`](https://api.emberjs.com/ember/release/classes/Route/methods/model?anchor=model) hook._
Copy link
Member Author

Choose a reason for hiding this comment

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

Because the reader hasn't seen the code yet, I thought it'd be better to move this paragraph (an afterthought about Model vs. model()) after we present the code.

@ijlee2 ijlee2 marked this pull request as ready for review September 25, 2020 13:20
@ijlee2 ijlee2 requested a review from a team September 25, 2020 13:20
@jenweber
Copy link
Contributor

I very vaguely recall that we did the store injection on purpose in the code samples, and I don’t remember why. Could you reach out to the dev-ember-data channel to get feedback on this? Thanks! The wording changes seem great regardless.

@acorncom
Copy link
Member

From what I remember, the Ember Data team would like to move away from having the store injected automatically in all the places. Long term, switching to specified injection (vs automated injection) likely leads to less error prone tree-shaking as app authors have “opted in” more clearly to using the store service

@ijlee2
Copy link
Member Author

ijlee2 commented Sep 26, 2020

Jen and David, thanks for providing feedback and additional context.

I think it makes sense that, in Octane and going forward, we will want developers to begin practicing being more explicit with dependency injection. At the same time, I wonder if, until initializeStoreInjections can be removed from Ember Data (code), it'd be better for Ember Guides to document what's current common practice.

As an intermediate step, I think we can also consider the option of reviewing all pages in the Ember Guides (in v3.15 and above), to ensure that the injection of store occurs whenever there's a reference to this.store and Ember Data. What I wouldn't want is for some pages to show injection of store service and others not, which may confuse developers.

Yep, I will reach out to the #dev-ember-data channel and ask for more feedback. Thanks again!

@acorncom
Copy link
Member

acorncom commented Sep 26, 2020

At the same time, I wonder if, until initializeStoreInjections can be removed from Ember Data (code), it'd be better for Ember Guides to document what's current common practice.

@ijlee2 I think given the end desire expressed by the Ember Data team at the very end of the issue here (emberjs/data#6166) it’s probably wiser to be steering community members toward the new best practices that we want them to be using in the future.

But yes, fully agreed that it should be standardized

@ijlee2
Copy link
Member Author

ijlee2 commented Sep 27, 2020

@acorncom Sounds good! When I get a chance, I'll check which pages don't currently show store injection. It's possible that all pages do and I can just revert the change that I made in this PR.

@ijlee2
Copy link
Member Author

ijlee2 commented Sep 28, 2020

I ran git grep -n store inside the source/release directory. Afterwards, I visited the relevant pages to see if we need to add @service store.

There are several places where we encourage implicit store injection. In a few other places, including the Super Rentals Tutorial, we do practice explicit store injection. Probably let's change implicit to explicit in a separate PR?

@ijlee2 ijlee2 closed this Oct 15, 2020
@ijlee2 ijlee2 deleted the update-how-to-inject-store branch October 15, 2020 16:13
@ijlee2 ijlee2 restored the update-how-to-inject-store branch October 15, 2020 16:13
@ijlee2
Copy link
Member Author

ijlee2 commented Oct 15, 2020

Closed by mistake.

@ijlee2 ijlee2 reopened this Oct 15, 2020
Copy link
Contributor

@jenweber jenweber left a comment

Choose a reason for hiding this comment

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

This looks good to me! I am not totally clear on whether you wanted to do more work on this before merging, so I'm not merging yet. Feel free to push the green button if you are ready!

@ijlee2
Copy link
Member Author

ijlee2 commented Oct 16, 2020

Thanks! I'll merge this PR and make a separate issue that asks for injecting the store service explicitly.

@ijlee2 ijlee2 merged commit 688caee into ember-learn:master Oct 16, 2020
@ijlee2 ijlee2 deleted the update-how-to-inject-store branch October 16, 2020 02:39
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.

3 participants