What is the equivalent of react context in glimmerjs?

411 Views Asked by At

I've been using react for the past three years and just watched a few talks about ember and glimmer and got interested in glimmer. So excuse my ignorance if the question doesn't make sense.

What will be an equivalent of a global state / context in a glimmer app? What I'm looking for is a @tracked data which can be accessed deep in the component tree without passing it as argument at each level. Think redux without all those ceremonial action/action-creator/reducer.

A single global atom with bunch of functions to immutably modify it and re-actively see the change on the component tree.

2

There are 2 best solutions below

0
On BEST ANSWER

Perhaps you are wanting to use services?

https://guides.emberjs.com/release/applications/services/

Services are app level state, and you can use 'injections' to get access to them deep in your component tree, similar to UseContext.

Also, you may be interested in this: https://www.notion.so/Ember-For-React-Developers-WIP-556a5d343cfb4f8dab1f4d631c05c95b (at http://emberatlas.com, in case the page gets renamed)

There is a section on global state / services / contexts

Note: Glimmer components are not the default component until ember 3.14

2
On

Based on your question the answer is no, at least not yet. Glimmer hasn't made it to v1 yet so maybe open an issue for an enhancement on the glimmer github page

you might also want to look into glimmer-redux