-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Properties of Easing object can reassignment #610
Comments
What if we apply Object.freeze? |
With this in view, I did some research on how to implement it.
There was also a review of whether to include the type definition of EasingFunctionGroup in Easing.ts. ProposalBased on these results, I modify the proposal.
This is a sample of Easing.ts export type EasingFunction = (amount: number) => number
export type EasingFunctionGroup {
In: EasingFunction
Out: EasingFunction
InOut: EasingFunction
}
export const Linear = Object.freeze({
None: (amount: number): number => {
return amount
},
})
export const Quadratic = Object.freeze(<EasingFunctionGroup>{
In: (amount: number): number => {
return amount * amount
},
Out: (amount: number): number => {
return amount * (2 - amount)
},
InOut: (amount: number): number => {
if ((amount *= 2) < 1) {
return 0.5 * amount * amount
}
return -0.5 * (--amount * (amount - 2) - 1)
},
}) TestI tested this sample in these environments
If I did not ignore tsc errors intentionally, I got the best results. If you find any problems with this proposal, please let me know. |
related : tweenjs#610
related : tweenjs#610
@MasatoMakino Hello again. sorry for taking so long. Let's apply const Easing = Object.freeze({
Linear: Object.freeze({
None: function (amount: number): number {
return amount
},
},
// ... etc ...
})
export default Easing; // same export, no breaking change |
Another idea is using |
By the way also @MasatoMakino, are you interested to join the org to help maintain and expand Tween.js? I sent you an invite. |
Description
All properties of the
TWEEN.Easing
object allow reassignment.Expected Behavior
Easing functions and groups in
TWEEN.Easing
do not allow reassignment.Actual Behavior
Easing functions and groups in
TWEEN.Easing
allow reassignment.Steps to Reproduce
Open code pen
This is a problem section.
This code can be run without causing any errors.
Impact
In any scope,
Easing
can be reassignment. If someone accidentally reassignment easing functions, it will be difficult to identify the problem.Proposal
Ideally, if we try to reassign to TWEEN.Easing, we will get an error.
Even if no error is thrown, this issue will be resolved if the reassignment is ignored.
Easing
global objectimport * as Easing from ". /Easing.ts"
With this change, I think it will possible to ignore reassignments without losing compatibility.
Environment
macOS 10.15.7
Google Chrome 90.0.4430.93
tween.js 18.6.4
The text was updated successfully, but these errors were encountered: