-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Ngrx component setup #2046
Ngrx component setup #2046
Conversation
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.
This is awesome 🎉
I've found some typos in the docs 👀
Preview docs changes for 82b07b8 at https://previews.ngrx.io/pr2046-82b07b8/ |
Thanks for the review @timdeschryver ! |
@BioPhoton Are you looking for feedback on the documentation here? I'm happy to review, if so. |
Also, if you add
to |
@jtcrowson Yes i look for feedback on the idea. Also the pocs could be looked at. But the main thing here is the idea and features included |
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.
Hello there!
Fixed a few typos.
This sounds promising!
Thanks @MikeRyanDev for introducing this at AngularConnect 2019.
Go Michael! 👏 |
Nice! |
Hi all, ATM I'm working on the performance optimizations with zone-less applications and the new component package. I'm trying to get a good overview before I start hacking so the following information may contain miss assumptions. Please correct me wherever needed! I already tested out some techniques with @JiaLiPassion and created a configurable RxJS operator for it. This operator acts as a rate-limiting operator on the event-loop level. I create 2 variants, one that filters and one more like a side effect operator like a tap that fires the side effect based on some condition. function observeOncePerAnimationFrame<T>(
// the e.g. our CD call
work: () => void,
// configuration to define the scope and provide a reference to the animationFrame reference (zone patched it so we cant use `requestAnimationFrame` directly
cfg: {
// by default the coalescing works app-wide.
// Key to this problem will be to find the right scoping here
context: window,
// in Angular zone patches the animation frame so we have to provide the unpatched one in our case
requestAnimationFrameRef: requestAnimationFrame,
}
)
}
// == Usage ===
changes$.pipe(
observeOncePerAnimationFrame(this.cdRef.detectChanges)
).subscribe(); The big challenge is to find the right approach for scoping the CD coalescing. What does it mean? Problem: If we run zone-full When running zone-less Angulars can't detect the changes and so can't coalesce them, so we need to come up with our own strategy. So if multiple changes happen at the same moment they will fire multiple CD calls. Research: If we start to dig in we realize there are different situations, the EmbeddedViewRef is eighter a reference to the parent view or the child component or template scope, depending on the usage.
{{observable$ | push}} This situation is valid for the
<ng-container *let="observable$ as o"></ng-container>
<simple-component [value]="observable$ | push as o"></simple-component> This situation is valid for the With this information, let's think about the coalescing problem again. First Thoughts: In the case of the push pipe placed as template interpolation, we could coalesce all CD calls within the component as only one call is needed, no matter if we bind the same observable multiple times or multiple different observables. In the case of *let and the push pipe use as template binding, we can use it's EmbeddedViewRef pointing to the child as a reference and coalesce multiple changes within a template scope. Other *let directives next to it will trigger separately and could fire in the same tick to update it's scope of the template. This is good if we have other bindings and bad if we bind the same observable at another place in the template. |
Unlike What does
|
4126aee
to
da9484c
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.
@BioPhoton I resolved some merge conflicts after bringing the ngrx branch up to date.
If you're working on it on your branch, don't forget to pull my merge commit in 🙂
Could you also clean up the unused files (did the merge go wrong?), for example we now have a push
and push$
.
There are also some linting errors, these can't be seen in our CI because it's currently failing. Once these comments are resolved, we should see the linting errors on the CI server.
@timdeschryver There must be something completely wrong as you comment on files I deleted a long time ago. We can maybe try to get your changes cherry-picked out and merged into mine? What should we do? I assume I have some inconsistencies on my side too and therefore thewhole thing happened. The hooks thing is e.g. one thing I deleted I guess a month ago or so... |
The described situation works for zone-full applications for sure. For zone-less I'm not sure. I will invest in this in the next days. Also markDirty schedules an app.tick. This would trigger rerendering (or at least the check for it) everywhere? right? |
Yes, the internal |
Important to say here is that we can coalesce the detectChanges call within a component or embedded view: #2046 (comment) |
Why is that, Michael? |
Not true. Two main issues to be aware of:
|
Please correct me if needed. {{observable$ | push}} revieves a different cdRef (EmbeddedView) than <ng-container *ngIf="observable$ | push as o">
{{o}}
</ng-container> does. The first is meant by component the second by embedded view. |
I just ran another experiment to rediscover what I learned when we were trying to manage change detection without Zone.js. In Ivy
They are all separate instances of a |
Ha!! I had the right instinct!
What about directives (*ngrxLet)? Also, I don't see the difference between component and pipe in template expression. It's hard for me to find but I assume that |
|
Update: Demo here: |
Hi @alexzuza, The issue: angular/angular#33677 There are 2 PRs I found provided a solution for it. None of them merged. What is your status? Do you know more? Thanks, Michael! |
Thanks for the work @BioPhoton! As discussed, we are proceeding with merging this in, and following up with additional PRs for cleanup. |
* Included Features: | ||
* - Take observables or promises, retrieve their values and render the value to the template | ||
* - Handling null and undefined values in a clean unified/structured way | ||
* - Triggers change-detection differently if `zone.js` is present or not (`detectChanges` or `markForCheck`) |
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.
@BioPhoton PushPipe in zone-less mode uses detectChanges which triggers change detection synchronously. Isn’t it better to markForCheck and schedule CD (appref.tick) on at least the next requestAnimationFrame?
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.
Hi @eugene-stativka !
Definitely!
I summed everything related to this problem in a document here:
https://hackmd.io/42oAMrzYReizA65AwQ7ZlQ
Please let me know the feedback here: #2441
Is it OK to start use this lib in my Project ?? Since its still under development or ?? @BioPhoton |
Move the content to #2441