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
Observable types #8431
Observable types #8431
Conversation
Build Stats
|
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.
src/canvas.class.ts
contains the fixes done in the PR
* array of objects starting from the object that triggered the call to the current one | ||
*/ | ||
path?: Group[]; | ||
[key: string]: any; |
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.
todo in follow up
src/shapes/itext.class.ts
Outdated
import { FabricObject } from './fabricObject.class'; | ||
|
||
export type ITextEvents = TObjectEvents & { |
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.
todo in #8420
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.
extracted all event types from src/typedefs.ts
to src/EventTypeDefs.ts
pointer: Point; | ||
}; | ||
|
||
export type TModificationEvents = |
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.
Up to here are types from typedefs
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 to MERGE
@ShaMan123 i changed the description of the PR with the one i would have loved to find when i approached the PR.
this process requires time, an introduct really helps |
I am taking a look now |
Seems I managed to enable passing other events that are not part of the spec, with an additional overload to import { FabricObject } from "./fabricObject.class";
import { Group } from "./group.class";
new FabricObject({}).on('resizing',opt=>opt.)
new FabricObject({}).on('',opt=>opt.)
new FabricObject({}).on('resizing1',(opt)=>opt.)
new Group({}).once('layout',opt=>opt.)
new Group({}).on('dgdfg', (opt: { a: boolean }) =>opt.)
new Group({}).on({
'mousedown:before':opt=>opt.transform,
'mousedown':opt=>opt.button,
'added': opt => opt.target,
}) Untitled-1.ts.-.fabric.js.-.Visual.Studio.Code.2022-11-20.13-17-24_Trim.3.mp4 |
Added IText event spec. |
Gave a stab at solving conflicts |
Joining now. |
This PR is an example why #8394 is important |
I understand that. To be honest i don't even expect this kind of complexity in types, i don't think TS should be a replacemente for documentation. |
Hmmm that is a good point, cause I do, now that you raised it. That is how I work. READY to merge |
This is vague |
Meaning that i m looking at things in order of priority to close the TS migration. |
src/EventTypeDefs.ts
Outdated
selected: never; | ||
deselected: never; |
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.
to me looks like that selected and deselected do get target
and optionally 'e' ( if they happen by mouse )
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 recall that the object is fired without context
But need to double check
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 opposed to the events fired on canvas
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 verified and added e + target.
I think we should merge and come back to it if necessary |
Motivation
Enforce strict typing for events handlers in the Observables.
Description
This PR showcases the pros of TS.With it using the observable is so easy and fun.Found a few discrepancies in the code and fixed them.This PR add a type definition file that describes in minute detail every event fired by fabricJS.
Events are divided by kind, transformation events, selection events, canvas/group events ( add and remove from the object tree), and interaction events.
Every class then takes a dynamic type of event type that is used to bring down to Observable class the type of event that will fire.
Doing so when using the on function for example, Typescript will be able to suggest what events are available and what options are available in the callback.
There are no functional changes on top of that, apart some event property change that has been found clashing with types and so fixed.
The changed events are:
target
but it seems to me thatdeselected
makes more sense )Changes
Gist
In Action