-
Notifications
You must be signed in to change notification settings - Fork 898
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
chore(dialog): change animation properties to methods #5464
base: main
Are you sure you want to change the base?
chore(dialog): change animation properties to methods #5464
Conversation
Hm, conceptually I think they're still properties in the sense that they're expected to be written, unlike a method which is usually expected not to be changed. Open to arguments why they should be considered methods though! |
Sorry I don't really have any arguments but for the sake of learning I want to ask why are they considered functions then? why not |
There's little technical difference between them. Methods share the same prototype function implementation, while properties are unique per instance. class Foo {
propFunction = () => true;
methodFunction() { return true; }
}
const fooOne = new Foo();
const fooTwo = new Foo();
console.log(fooOne.propFunction === fooTwo.propFunction); // false
console.log(fooOne.methodFunction === fooTwo.methodFunction); // true
Technically though, yes, changing it to a shared function instance should theoretically be more performant since we're not creating a new JS function instance per class instance. I doubt there's a measurable impact though. |
Oops sorry @asyncLiz I meant why they should be functions and not an object directly? class Foo {
openAnimation = DIALOG_DEFAULT_OPEN_ANIMATION
// instead of getOpenAnimation() => DIALOG_DEFAULT_OPEN_ANIMATION
} |
I originally made them functions so that users could have more options to create dynamic animations. dialog.getOpenAnimation = () => {
if (isM3()) {
return DIALOG_DEFAULT_OPEN_ANIMATION;
}
// A different animation for an app that is
// iteratively upgrading from M2 to M3
return M2_MIGRATION_DIALOG_OPEN_ANIMATION;
}; This is just my opinion on what's useful. Would love to hear your dev experience on how you're typically overriding the animations! Lit binding, setting the prop directly, extending, etc. We could make them both properties and methods if it's convenient devx to bind an object. For example, in a lit binding it's more verbose and creates a function: html`
<md-dialog .openAnimation=${OPEN_ANIMATION}>
<!-- vs -->
<md-dialog .getOpenAnimation=${() => OPEN_ANIMATION}>
`; |
It just caught my eyes in the docs that's all, I think functions are more handy yes. But in that case we might want to add the keyword |
I'm not sure I know a good use case for why animation generation would need to be asynchronous to justify introducing |
Moving
getOpenAnimation
andgetCloseAnimation
properties to methods type for the doc: