[](https://badge.fury.io/js/window-resize-subject) [](https://opensource.org/licenses/MIT) 

!CI
> Handler for the window resize event of the observer pattern.
npm
``bash`
$ npm i window-resize-subject
yarn
`bash`
$ yarn add window-resize-subject
`js
import { WindowResizeSubject } from 'window-resize-subject';
// create subject
const subject = new WindowResizeSubject();
// add observer
const observer = ({ width, height }) => {
// do something
};
subejct.addObserver('name', observer);
// start watching the resize event
subject.subscribe();
`
> note: You can also write in a method chain
`js`
subejct.addObserver('name', observer).subscribe();
- params:
- name:
- type: string | SymbolWindowResizeObserver
- observer:
- type: (event: { width: number, height: number }) => void
- details:
Add observer.
And called with the current window size.
`js`
subejct.addObserver('name', ({ width, height }) => {
// do something
});
Start watching the resize event.
Stop watching the resize event.
> note: observer is not deleted.
- params:
- size:
- type: Objectnumber
- width: number
- height:
Force update.
`js`
subject.notifyObservers({ width: 800, height: 600 });
- params:
- name:
- type: string | Symbol
Deletes the specified Observer.
`js`
subject.deleteObserver('name');
Deletes all Observers.
- params:
- type: number
Changes the delay time for a resize event.
`js`
subject.setDelay(100);
returns true if it has an observer.
Dispatches the current window size.
- type: number33
- default:
Changes the delay time for a resize event.
`js
import { WindowResizeSubject } from 'window-resize-subject';
const subject = new WindowResizeSubject({ delay: 100 });
``
If you find a bug or want to contribute to the code or documentation, you can help by submitting an issue or a pull request.