-
Notifications
You must be signed in to change notification settings - Fork 25.9k
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
fix(animations): generate aot code for animation trigger output events #12291
Conversation
@tbosch Also, we now explose |
e78a4bc
to
f655e78
Compare
Aot Sample: _View_App0.prototype.detectChangesInternal = function(throwOnChange) {
var self = this;
var transitionAnimation = null ;
var currVal_4 = self.context.openClose;
if (jit_checkBinding6(throwOnChange, self._expr_4, currVal_4)) {
var oldRenderVar = self._expr_4;
if ((oldRenderVar == jit_UNINITIALIZED5) ) {
(oldRenderVar = 'void');
}
var newRenderVar = currVal_4;
if ((newRenderVar == jit_UNINITIALIZED5) ) {
(newRenderVar = 'void');
}
transitionAnimation = self.componentType.animations['myTrigger'](self, self._el_8, oldRenderVar, newRenderVar);
self._expr_4 = currVal_4;
}
if (transitionAnimation) {
transitionAnimation.player.onDone(self.eventHandler(self._handle_myTrigger_8_0.bind(self, transitionAnimation)));
}
if (transitionAnimation) {
transitionAnimation.player.onStart(self.eventHandler(self._handle_myTrigger_8_1.bind(self, transitionAnimation)));
}
self.detectContentChildrenChanges(throwOnChange);
self.detectViewChildrenChanges(throwOnChange);
} |
main refactorings:
|
f655e78
to
374d991
Compare
Codegen looks like this now: _View_App0.prototype.detectChangesInternal = function(throwOnChange) {
var self = this;
var currVal_4 = self.context.openClose;
if (jit_checkBinding6(throwOnChange, self._expr_4, currVal_4)) {
var oldRenderVar = self._expr_4;
if ((oldRenderVar == jit_UNINITIALIZED5) ) {
(oldRenderVar = 'void');
}
var newRenderVar = currVal_4;
if ((newRenderVar == jit_UNINITIALIZED5) ) {
(newRenderVar = 'void');
}
var animationTransition_myTrigger = self.componentType.animations['myTrigger'](self, self._el_8, oldRenderVar, newRenderVar);
animationTransition_myTrigger.onDone(self._handle_myTrigger_8_0.bind(self));
animationTransition_myTrigger.onStart(self._handle_myTrigger_8_1.bind(self));
self._expr_4 = currVal_4;
}
self.detectContentChildrenChanges(throwOnChange);
self.detectViewChildrenChanges(throwOnChange);
}; |
374d991
to
ed328c5
Compare
ed328c5
to
af0e84f
Compare
@@ -172,12 +176,32 @@ function bindAndWriteToRenderer( | |||
[newRenderVar.set(emptyStateValue).toStmt()])); |
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.
Remove the variables oldRenderVar
and newRenderVar
, and use a ternary expression instead.
...animationFnExpr.callFn([o.THIS_EXPR,
oldRenderValue.equals(o.importExpr(resolveIdentifier(Identifiers.UNINITIALIZED))
.conditional(oldRenderVar, emptyStateValue)),
newRenderValue.equals(o.importExpr(resolveIdentifier(Identifiers.UNINITIALIZED))
.conditional(newRenderVar, emptyStateValue)),
...
@@ -290,7 +292,7 @@ class _AnimationBuilder implements AnimationAstVisitor { | |||
new o.FnParam(_ANIMATION_CURRENT_STATE_VAR.name, o.DYNAMIC_TYPE), | |||
new o.FnParam(_ANIMATION_NEXT_STATE_VAR.name, o.DYNAMIC_TYPE) | |||
], | |||
statements); | |||
statements, o.DYNAMIC_TYPE); |
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 should be o.importType(resolveIdentifier(Identifiers.AnimationTransition))
, as the factory returns an AnimationTransition
, right?
@@ -10,6 +10,7 @@ import {CompileDirectiveMetadata} from '../compile_metadata'; | |||
import {isPresent} from '../facade/lang'; | |||
import {identifierToken} from '../identifiers'; | |||
import * as o from '../output/output_ast'; | |||
import {ViewType} from '../private_import_core'; |
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 needed
listener.listenToAnimation(); | ||
} else { | ||
// the animation listeners are handled within property_binder.ts to | ||
// allow then to be placed next to the animation factory statements |
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.
typo: allow them...
compileMethod = view.animationBindingsMethod; | ||
|
||
const _ANIMATION_TRANSITION_VAR = o.variable('animationTransition_' + animationName); |
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.
remove _
prefix, and don't upper case everything. This is just a variable here, not a constant defined at the top leve.
compileMethod = view.animationBindingsMethod; | ||
|
||
const _ANIMATION_TRANSITION_VAR = o.variable('animationTransition_' + animationName); |
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.
Move this further down, right before you declare the variable (as it is not used before that).
view.detachMethod.addStmt( | ||
animationFnExpr.callFn([o.THIS_EXPR, renderNode, oldRenderValue, emptyStateValue]) | ||
.toStmt()); | ||
detachStmts.push(_ANIMATION_TRANSITION_VAR |
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 are we always creating the animation again on view detach?
eventListeners.forEach(listener => { | ||
if (listener.isAnimation && listener.eventName === animationName) { | ||
let callbackMethod = listener.eventPhase == 'start' ? 'onStart' : 'onDone'; | ||
let transitionEvent = o.variable('e'); |
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 variable is not used any more.
_ANIMATION_TRANSITION_VAR | ||
.callMethod( | ||
callbackMethod, | ||
[o.THIS_EXPR.prop(listener.methodName).callMethod('bind', [o.THIS_EXPR])]) |
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.
Use .callMethod(o.BuiltinMethod.Bind, ...
, don't pass in bind
as a string.
|
||
eventListeners.forEach(listener => { | ||
if (listener.isAnimation && listener.eventName === animationName) { | ||
let callbackMethod = listener.eventPhase == 'start' ? 'onStart' : 'onDone'; |
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.
Move the logic here into CompileEventListener.listenToAnimation
.
private _totalTime: number; | ||
|
||
constructor( | ||
public player: AnimationPlayer, |
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 does the player need to be public?
|
||
constructor( | ||
public player: AnimationPlayer, | ||
{fromState, toState, totalTime}: {fromState: string, toState: string, totalTime: number}) { |
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.
Don't use named arguments here, just positional ones and declare the fields as well. E.g.
constructor(private _player: AnimationPlayer, private _fromState: string, ...) {}
fromState: string; | ||
toState: string; | ||
totalTime: number; | ||
phaseName: string; |
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.
Please ping @IgorMinar whether this is a breaking change, and we need to make this field optional. I don't expect users to new up their own AnimationTransitionEvent
.
af0e84f
to
b5702b1
Compare
private _totalTime: number) {} | ||
|
||
/** @internal */ | ||
_createEvent(phaseName: string): AnimationTransitionEvent { |
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 not private
b5702b1
to
6466f4b
Compare
6466f4b
to
7d0a494
Compare
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. |
No description provided.