You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just wanted to throw a thought out there, has it ever been considered to run ngrx/effects on a web worker? It seems like pretty prime case for it given that it subscribes to messages and responds with a message and doesn't access the DOM. There would obviously be some challenges like getting the latest state from the store but I feel like; at least in the way that I use ngrx this might work well, my reducers are pure and simple my views only subscribe to observable from the store and my effects do all of the heavy lifting.
I like this idea, a lot, and we should make this A Thing. cc @jeffbcross@alxhub
Would be reasonably straightforward to use angular/core (for DI) run effects in the background, and implement a simple bridge API that handles piping actions to the appropriate remote thread.
cc @surma cuz this would probably be pretty neato with some of your API sketches...
Reacted by antonyRoberts, nihique, Gaurav Mukherjee , Elwyn, Craig Spence, Vignesh Jagadeesh, Steven, Oleg Pimenov, Fabien Dehopré, Alexander Heimbuch and 43 more
Reacted by Wis, bmayen, Jan Laureys, Vlad Miller, Mark Pieszak, Sandy, Toni Villena and Ksenia Sadrina
I have been working on an API proposal to make off-thread work much much easier/convenient. Please see the Explainer in the repository.
@bfgeek and I have been working on a polyfill the last couple of days (still on a branch), but it’s close to being done so I’d love for y’all to test it out.
wouldn't the Angular worker, solve this?
as I understand it, all app logic (should include ngrx?) on a worker (which is on a 2nd thread), with angular rendering on the main thread. the issue is not proposing having the state also on the worker (it cant b/c state service), or is it?
what comes to my mind is what I once read on the NativeScript blog or their GH repo; that serializing/ +marshaling can result in worst performance. IIRC, isn't that why react team chose not to do vdom diffing on a worker? obviously NG is different+better with CD with zones.. I hope results are too.
on the other hand
iOS and Android native platforms, for example, restrict (by default) the usage of any APIs not critical to UI manipulation on the main thread.
and 4. are pseudo-code, they won't work. As soon as I import anything - even just the Action interface, the app will no longer build:
By making my worker code a whole lot more ugly and bypassing any references to @ngrx, I managed to make this work.
What needs to be done:
Trace and hopefully resolve build errors when referencing interfaces and actions of @ngrx/store and @ngrx/effects. We will probably need at least ActionsSubject, Action, ofType inside the web worker to make the code much cleaner.
Introduce a module that sets up the bridge between the Angular app and the worker (basically step 2.)
Introduce utilities that make coding the worker easier, as described in steps 3 and 4
Activity
surma commentedon Aug 9, 2017
Oh this is interesting! For context:
I have been working on an API proposal to make off-thread work much much easier/convenient. Please see the Explainer in the repository.
@bfgeek and I have been working on a polyfill the last couple of days (still on a branch), but it’s close to being done so I’d love for y’all to test it out.
wis commentedon Aug 9, 2017
wouldn't the Angular worker, solve this?
as I understand it, all app logic (should include ngrx?) on a worker (which is on a 2nd thread), with angular rendering on the main thread.
the issue is not proposing having the state also on the worker (it cant b/c state service), or is it?
what comes to my mind is what I once read on the NativeScript blog or their GH repo; that serializing/ +marshaling can result in worst performance. IIRC, isn't that why react team chose not to do vdom diffing on a worker? obviously NG is different+better with CD with zones.. I hope results are too.
on the other hand
you are the experts here anyways.
PTC-JoshuaMatthews commentedon Jun 13, 2018
Maybe something like this would work with ngrx?
https://blog.angularindepth.com/angular-with-web-workers-step-by-step-dc11d5872135
tadamczak commentedon Mar 20, 2019
Bump. Is there any official solution to use effects inside web workers? Or general integration with ngrx?
robwormald commentedon Apr 25, 2019
With Web Worker support landing in CLI, we should revisit this.
alexdor commentedon Jan 29, 2020
Now that the web workers have landed, should this be revisited?
webberig commentedon Jun 1, 2020
I've been giving this idea a try, i'd like to share my approach:
create a web worker
Basically, this: https://angular.io/guide/web-worker
emit actions to the worker
I put this in my app.component:
Actioninterface, the app will no longer build:By making my worker code a whole lot more ugly and bypassing any references to @ngrx, I managed to make this work.
What needs to be done:
Trace and hopefully resolve build errors when referencing interfaces and actions of @ngrx/store and @ngrx/effects. We will probably need at least
ActionsSubject,Action,ofTypeinside the web worker to make the code much cleaner.Introduce a module that sets up the bridge between the Angular app and the worker (basically step 2.)
Introduce utilities that make coding the worker easier, as described in steps 3 and 4
david-shortman commentedon Feb 25, 2021
This seems like an interesting project to pursue.
So I'd like to know what the typical path for larger NgRx features like this take. Something like
I'd be interested in working on this but would look to the maintainers for guidance on starting.
MartinFreire commentedon Mar 26, 2021
I just commented something about this issue in the other issue, i hope it helps
#195 (comment)
Thanks!