-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Last month we were introduced to validateAndUnwrapRefs, a hook available in the repo that allow us to validate and unwrap refs.
While this hook prevents some past issues (ex: adding non-available refs to tweens), it also creates an extra condition across all the animation methods. Here's an example of the previous implementation and the new one:
export function createInAnimation(refs: ComponentRefs): gsap.core.Animation {
const { self } = assertAndUnwrapRefs(refs);
const timeline = gsap.timeline();
timeline.add(fadeFromTo(self));
return timeline;
}export function createInAnimation(refs: ComponentRefs): gsap.core.Animation {
const [isValid, unwrappedRefs] = validateAndUnwrapRefs(refs);
const timeline = gsap.timeline();
if(isValid) {
const { self } = unwrappedRefs;
timeline.add(fadeFromTo(self));
}
return timeline;
}At first glance this doesn't look like much but on projects that rely on animation this can stack up. In my opinion the methods created in the *.animations.ts should focus more on the timeline tweens and less on checking if elements are available, so I propose that this validation is taken care at the hooks level.
I think the animation method should not be executed in case validations pass. We can have a parameter to make those validations optional, for cases where we want to handle the validation at the animation method level.
Would love to hear some opinions and solutions to make this implementation smoother.