Skip to content

Application State - #2237

Open
NullVoxPopuli wants to merge 1 commit into
masterfrom
nvp/lifetimes-of-state
Open

NullVoxPopuli wants to merge 1 commit into
masterfrom
nvp/lifetimes-of-state

Conversation

@NullVoxPopuli

@NullVoxPopuli NullVoxPopuli commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

This is necessarily entangled with

image

NOTE: these things make dealing with state easier than ember's docs currently describe (and remove some boilerplate in this PR):

I can, ofc, pursue shipping the RFCs above, but I would like more engagement from the core teams, and the RFCs will ofc need to be accepted

@netlify

netlify Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for ember-guides ready!

Name Link
🔨 Latest commit 6c4596f
🔍 Latest deploy log https://app.netlify.com/projects/ember-guides/deploys/6aa2f9fda5ece900088ce578
😎 Deploy Preview https://deploy-preview-2237--ember-guides.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@NullVoxPopuli
NullVoxPopuli marked this pull request as ready for review September 10, 2026 18:23

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm sad this doesn't show up as a mv :(


Ember gives you two ways to tie state to the owner: a plain class, described on this page, and a [Service](../services/).
Prefer the plain class because plain classes will participate in the import graph and naturally fit in to automatic bundle splitting (unlike services).
Use a Service only for the small, minimally required, set of state that the application needs to boot.

@johanrd johanrd Sep 11, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for the read (again). This section is very interesting to me – As long time ember user, I have never considered plain es module class state as a good alternative to Services (except for a few cases of caches I use). This also begs the question for me in this read: Why should I not replace all services with plain classes?

What is special about services that makes them better fit for "the state that the application needs to boot.", than plain classes? (Isn't there a way to make es class es available on app boot?).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

why should I not replace all services with plain classes

if they are not needed for boot, I argue you absolutely should use plain classes. The closer we get to vanilla javascript the better, and more at-home developers will feel.

What is special about services that makes them better fit for "the state that the application needs to boot.", than plain classes? (Isn't there a way to make es class es available on app boot?).

if your vanilla class adheres to the same static api interface, you don't need to use Service from @ember/service at all, your intuition is correct here. (all you need is a static create function).

So in that regard, there is almost an argument for ditching Service entirely -- however the convenience of the interface abstraction is nice.

I drew the line at "minimally required state", such as the router service, because:

  • existing convention (we don't really have a convention for application state outside of this)
  • libraries may want to access the service, and given the worries brought up in the explicit service injection RFC, I think we can just teach to use the "string-service" system if someone can't get a hold of their dependency graph, or if they truely have no way to get a hold of a static reference (that isn't a string)

@johanrd johanrd Sep 13, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

thanks for the explanation. makes sense. I like that it shows a future of simple vanilla javascript, where Ember is not shy to get out of the way and embraces the platform.

There are some teaching downsides in explaining two concepts for application state, though – at least at the same level. The proposed text for the class based approach jumps straight into Owner, singleton, (and WeakMap), which may quite a steep learning curve?

We should maybe also run the thought: How should plain class state be taught when / if Service ever become more plain (i.e. keep most of the ergonimics, but get the benefits of cutting the cord of string based DI, etc.)

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.

2 participants