Skip to content

added ResizeCallback to ResizeSensor.d.ts and added static functions … #248

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

Merged
merged 3 commits into from
Nov 8, 2018
Merged

added ResizeCallback to ResizeSensor.d.ts and added static functions … #248

merged 3 commits into from
Nov 8, 2018

Conversation

coalman
Copy link
Contributor

@coalman coalman commented Nov 8, 2018

…to ResizeSensor class

This adds a ResizeCallback type instead of Function and adds the static detach/reset functions to ResizeSensor.

This allows the following:

const callback: ResizeSensorCallback = (size) => {
  console.log(size.width); // size.width is a number
  console.log(size.height); // size.height is a number
};

const sensor = new ResizeSensor(element, callback);
ResizeSensor.detach(element, callback); // type checked args
ResizeSensor.reset(element); // type checked args
sensor.detach(callback); // type checked arg
sensor.reset(); // type checked

detach(callback: ResizeSensorCallback): void;
reset(): void;

static detach(element: Element | Element[], callback: ResizeSensorCallback): void;
Copy link
Owner

@marcj marcj Nov 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

callback is optional here, can you mark it as such please? :)
Usually, you would want to call it without a callback and only necessary when you have multiple listener on the same element.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the optional for detach callbacks.

@marcj
Copy link
Owner

marcj commented Nov 8, 2018

Cool thanks!

@marcj marcj merged commit 9cb667d into marcj:master Nov 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants