-
Notifications
You must be signed in to change notification settings - Fork 27k
fix(ivy): support separate creation mode and update mode execution #23292
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
Conversation
489e95f to
677fd8c
Compare
|
You can preview c3e1c1d at https://pr23292-c3e1c1d.ngbuilds.io/. |
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.
Would it make sense to have a ParenthesizedExpression extending (and wrapping an) Expression instead ?
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.
Can you clarify a bit what you're proposing? The change here is to make parentheses optional because currently they are always added to every Expression (which includes BinaryOperatorExpr). This means that without this change, we'd get if ((rf & 1)) instead of if (rf & 1). I've added a parameter so you can remove the parentheses if you know the expression you're generating doesn't need them.
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.
as LViewNode should no more be required (*2)
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.
May be explain what is the context here and we have both Create and Update set vs when we have Create and Update distinct ?
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.
root -> first node ?
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.
In this case, it's not necessarily the first node. It's a node directly on the root component. I think in this case "root" is clearer because it's how we're referring to the same nodes elsewhere.
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.
maybe add that this is a bound text node add xlink the place where there are usually created.
vicb
left a comment
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.
- not sure about theimplementation for
ast.parens? - not sure about why we move var declaration to const outside of the Update and Create blocks (may be needs an ex of where it would not work ?),
- a few nits
Overall great changes !
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.
Why did we gain a new method here?
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.
We're not actually gaining any new code; I just refactored a duplicative part of textBinding, addRemoveView, and text into one shared function.
|
You can preview 1afd4e1 at https://pr23292-1afd4e1.ngbuilds.io/. |
|
You can preview d9713d2 at https://pr23292-d9713d2.ngbuilds.io/. |
…nd update mode blocks
|
You can preview 45d5c5f at https://pr23292-45d5c5f.ngbuilds.io/. |
| */ | ||
| function initBindings() { | ||
| bindingIndex = currentView.bindingStartIndex = data.length; | ||
| currentView.bindingIndex = currentView.bindingStartIndex = data.length; |
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.
currentView.bindingIndex should be null when entering the fn right ?
Add an assert
| cleanup = newView && newView.cleanup; | ||
| renderer = newView && newView.renderer; | ||
|
|
||
| if (newView && newView.bindingIndex == null) { |
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.
nit: === null
| tail: null, | ||
| next: null, | ||
| bindingStartIndex: null, | ||
| bindingIndex: null !, |
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.
What about either have a number|null type or using -1 ? (and get ride of that ugly !)
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.
Yeah, I originally had it as number|null, but then you have to use the ! everywhere that you increment the binding index (which ends up being more ! overall)
…nd update mode blocks
|
You can preview 7d30e19 at https://pr23292-7d30e19.ngbuilds.io/. |
…nd update mode blocks
|
You can preview 63920c5 at https://pr23292-63920c5.ngbuilds.io/. |
…nd update mode blocks
|
You can preview 92cabc7 at https://pr23292-92cabc7.ngbuilds.io/. |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Currently, the update block (i.e. binding refresh) always runs with the creation block (i.e. creating elements / directives) because of the way template functions are constructed. While this is the correct behavior for most templates, this limitation breaks dynamically created views because structural directives like
ngForexpect that the creation block runs separately from the update block, as it does in render2.This PR separates the execution of the creation block and update block, so they can run together or separately depending on what's appropriate. This is accomplished by replacing the boolean
cmparameter in template functions with an enum calledRenderFlags. Note that the order of the parameters has also been switched.Before:
After (flags written out for clarity):
After (actual output):
Notes:
createEmbeddedViewis called, only the creation block is run. The update block isn't executed untilrenderEmbeddedTemplateis called byrefreshDynamicChildrenat the end of the parent view's execution.Before:
After:
bindingStartIndex. This doesn't work anymore because bindings won't always run with creation mode, so thebindingStartIndexmight not be set. Now we have an explicit check tobindingStartIndex.ViewContainerRefwill try to insert it into the view before the text node has actually been created (update mode has not yet run at this point). In these cases, we have to create the text node at insertion, then update the value later.