window-resize-subject
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var WindowResizeSubject=function(){function e(e){var t=(void 0===e?{}:e).delay,i=void 0===t?33:t;this._observers=new Map,this._subscribed=!1,this._delay=i,this._handler=this._handleResize.bind(this)}return e.prototype.addObserver=function(e,t){return this._observers.set(e,t),this},e.prototype.deleteObserver=function(e){return this._observers.delete(e),this},e.prototype.deleteObservers=function(){return this._observers.clear(),this},e.prototype.notifyObservers=function(t){this._observers.forEach(function(e){e(t)})},e.prototype.subscribe=function(){return"undefined"==typeof window||this._subscribed||(this._update(),window.addEventListener("resize",this._handler),window.addEventListener("orientationchange",this._handler),this._subscribed=!0),this},e.prototype.unsubscribe=function(){return this._subscribed&&(window.removeEventListener("resize",this._handler),window.removeEventListener("orientationchange",this._handler),this._subscribed=!1),this},e.prototype.setDelay=function(e){this._delay=e},e.prototype.hasObserver=function(){return 0<this._observers.size},e.prototype._update=function(){this.notifyObservers({width:window.innerWidth,height:window.innerHeight})},e.prototype._handleResize=function(){var e=this;clearTimeout(this._timer),this._timer=setTimeout(function(){e._update()},this._delay)},e}();exports.WindowResizeSubject=WindowResizeSubject; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var WindowResizeSubject=function(){function e(e){var t=(void 0===e?{}:e).delay,i=void 0===t?33:t;this._observers=new Map,this._subscribed=!1,this._delay=i,this._handler=this._handleResize.bind(this)}return e.prototype.addObserver=function(e,t){return this._observers.set(e,t),this},e.prototype.deleteObserver=function(e){return this._observers.delete(e),this},e.prototype.deleteObservers=function(){return this._observers.clear(),this},e.prototype.notifyObservers=function(t){return this._observers.forEach(function(e){e(t)}),this},e.prototype.subscribe=function(){return"undefined"==typeof window||this._subscribed||(this._update(),window.addEventListener("resize",this._handler),window.addEventListener("orientationchange",this._handler),this._subscribed=!0),this},e.prototype.unsubscribe=function(){return this._subscribed&&(window.removeEventListener("resize",this._handler),window.removeEventListener("orientationchange",this._handler),this._subscribed=!1),this},e.prototype.setDelay=function(e){return this._delay=e,this},e.prototype.hasObserver=function(){return 0<this._observers.size},e.prototype._update=function(){this.notifyObservers({width:window.innerWidth,height:window.innerHeight})},e.prototype._handleResize=function(){var e=this;clearTimeout(this._timer),this._timer=setTimeout(function(){e._update()},this._delay)},e}();exports.WindowResizeSubject=WindowResizeSubject; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).bundle=e.bundle||{},e.bundle.umd=e.bundle.umd||{},e.bundle.umd.js={}))}(this,function(e){"use strict";var t=(i.prototype.addObserver=function(e,t){return this._observers.set(e,t),this},i.prototype.deleteObserver=function(e){return this._observers.delete(e),this},i.prototype.deleteObservers=function(){return this._observers.clear(),this},i.prototype.notifyObservers=function(t){this._observers.forEach(function(e){e(t)})},i.prototype.subscribe=function(){return"undefined"==typeof window||this._subscribed||(this._update(),window.addEventListener("resize",this._handler),window.addEventListener("orientationchange",this._handler),this._subscribed=!0),this},i.prototype.unsubscribe=function(){return this._subscribed&&(window.removeEventListener("resize",this._handler),window.removeEventListener("orientationchange",this._handler),this._subscribed=!1),this},i.prototype.setDelay=function(e){this._delay=e},i.prototype.hasObserver=function(){return 0<this._observers.size},i.prototype._update=function(){this.notifyObservers({width:window.innerWidth,height:window.innerHeight})},i.prototype._handleResize=function(){var e=this;clearTimeout(this._timer),this._timer=setTimeout(function(){e._update()},this._delay)},i);function i(e){var t=(void 0===e?{}:e).delay,i=void 0===t?33:t;this._observers=new Map,this._subscribed=!1,this._delay=i,this._handler=this._handleResize.bind(this)}e.WindowResizeSubject=t,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).bundle=e.bundle||{},e.bundle.umd=e.bundle.umd||{},e.bundle.umd.js={}))}(this,function(e){"use strict";var t=(i.prototype.addObserver=function(e,t){return this._observers.set(e,t),this},i.prototype.deleteObserver=function(e){return this._observers.delete(e),this},i.prototype.deleteObservers=function(){return this._observers.clear(),this},i.prototype.notifyObservers=function(t){return this._observers.forEach(function(e){e(t)}),this},i.prototype.subscribe=function(){return"undefined"==typeof window||this._subscribed||(this._update(),window.addEventListener("resize",this._handler),window.addEventListener("orientationchange",this._handler),this._subscribed=!0),this},i.prototype.unsubscribe=function(){return this._subscribed&&(window.removeEventListener("resize",this._handler),window.removeEventListener("orientationchange",this._handler),this._subscribed=!1),this},i.prototype.setDelay=function(e){return this._delay=e,this},i.prototype.hasObserver=function(){return 0<this._observers.size},i.prototype._update=function(){this.notifyObservers({width:window.innerWidth,height:window.innerHeight})},i.prototype._handleResize=function(){var e=this;clearTimeout(this._timer),this._timer=setTimeout(function(){e._update()},this._delay)},i);function i(e){var t=(void 0===e?{}:e).delay,i=void 0===t?33:t;this._observers=new Map,this._subscribed=!1,this._delay=i,this._handler=this._handleResize.bind(this)}e.WindowResizeSubject=t,Object.defineProperty(e,"__esModule",{value:!0})}); |
export declare type Observer<Event = void> = (event: Event) => void; | ||
export declare type ObserverName = string | Symbol; | ||
export interface Subject<Event = void> { | ||
addObserver(name: string, observer: Observer<Event>): this; | ||
deleteObserver(name: string): this; | ||
notifyObservers(event: Event): void; | ||
addObserver(name: ObserverName, observer: Observer<Event>): this; | ||
deleteObserver(name: ObserverName): this; | ||
notifyObservers(event: Event): this; | ||
subscribe(): this; | ||
@@ -7,0 +8,0 @@ unsubscribe(): this; |
@@ -1,2 +0,2 @@ | ||
import type { Subject, WindowResizeObserver, WindowResizeSubjectEvent } from './type'; | ||
import type { Subject, WindowResizeObserver, WindowResizeSubjectEvent, ObserverName } from './type'; | ||
export declare class WindowResizeSubject implements Subject<WindowResizeSubjectEvent> { | ||
@@ -11,9 +11,9 @@ private _observers; | ||
}); | ||
addObserver(name: string, observer: WindowResizeObserver): this; | ||
deleteObserver(name: string): this; | ||
addObserver(name: ObserverName, observer: WindowResizeObserver): this; | ||
deleteObserver(name: ObserverName): this; | ||
deleteObservers(): this; | ||
notifyObservers(event: WindowResizeSubjectEvent): void; | ||
notifyObservers(event: WindowResizeSubjectEvent): this; | ||
subscribe(): this; | ||
unsubscribe(): this; | ||
setDelay(delay: number): void; | ||
setDelay(delay: number): this; | ||
hasObserver(): boolean; | ||
@@ -20,0 +20,0 @@ private _update; |
{ | ||
"name": "window-resize-subject", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"main": "dist/index.common.js", | ||
@@ -5,0 +5,0 @@ "unpkg": "dist/index.umd.js", |
@@ -53,3 +53,3 @@ # window-resize-subject | ||
- name: | ||
- type: `string` | ||
- type: `string` | `Symbol` | ||
- observer: | ||
@@ -95,3 +95,3 @@ - type: `WindowResizeObserver` | ||
- name: | ||
- type: `string` | ||
- type: `string` | `Symbol` | ||
@@ -98,0 +98,0 @@ Deletes the specified Observer. |
9582
50