-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
BREAKING: remove object type
in favor of Class.name
#8714
Conversation
a step forward for default values
Build Stats
|
type
type
type
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.
ready
IMO most of filters fromObject
can be move to the base class
src/filters/ColorMatrixFilters.ts
Outdated
getType() { | ||
return super.getType(); | ||
} |
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.
TS complains since protected methods can't be in a mixin so I made it public
For 6.0 we will keep |
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.
updated from master
type
type
in favor of Class.name
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.
reverted changes made to filters
I want to remove isType
as well
The reason is that logic like isActiveSelection
or isTextObject
(and more from src/util/types.ts
) is not good enough anymore in case of an app subclassing these classes. It will fail the check, instanceof
is the migration path.
@asturur I want your feed back on this when you are done with filters |
The solution I can think about that doesn't involve |
we are not removing type nor chaning its value. |
It doesn't. |
I registered IText for example in |
exposing a getter as you did is a good option non the less |
yes is what i m doing, adding a getter for type and adding a test to verify old data works. |
I added tests in the class registry tests, take a look there |
@ShaMan123 looking at: I did some things:
Now before i change the tests from |
this[SVG].set( | ||
SVGTagName ?? classConstructor.name.toLowerCase(), | ||
classConstructor | ||
); |
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.
svg is always lowercase
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.
good point
src/Collection.ts
Outdated
if (types.length === 0) { | ||
return [...this._objects]; | ||
} | ||
return this._objects.filter((o) => types.includes(o.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.
not sure why this was deleted? also needs the lowercase/uppercase here too
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 isType
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.
return this._objects.filter((o) => types.includes(o.type)); | |
return this._objects.filter((o) => o.isType(...types)); |
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.
I suggest we define type
as following:
Object.defineProperty(this, 'type', {
enumerable: false,
// so we can define in subclass
configurable: true,
writable: false,
value: 'i-text',
});
this way trying to write over it will throw an error so all is good. The dev sees it and can easily migrate AND it is hidden from TS so TS will warn about it as well
What is wrong with the setter? i could not add the setter and we would get the error, but the error is exactly what i don't want because today the property is writable |
I don't mind. |
Breaking change we have a tons, so for now we are not adding more. |
@@ -54,7 +52,7 @@ export class Pattern { | |||
} | |||
|
|||
set type(value) { | |||
console.warn('Setting type has no effect', value) | |||
console.warn('Setting type has no effect', value); |
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 I said previously, I would prefer this to throw an error.
Think of an app that for some strange reason changes type. That app is now broken and the only indication is the console.
For the sake of discussion. The app that did that strange thing should pay the cost somehow.
Motivation
No values on prototype, continues the default value effort
Description
removed
type
since it was a readonly static propertyChanges
FabricObject
in class registry. Only to base fabric object was registeredBREAKING:
type
from all objects/filters. Useinstanceof
orisType
insteadisType
will not work for old types, you must pass the class name, that is whyinstanceof
is the recommended migration pathGist
In Action