windowed-observable
Advanced tools
Comparing version 0.4.0 to 0.4.1
@@ -1,1 +0,1 @@ | ||
export { Observer, ObserversArray, EventsArray, SubscriptionOptions, default as Observable, } from './observable'; | ||
export * from './observable'; |
export declare const EVENTS = "__events__"; | ||
export declare const SHARED = "__shared__"; | ||
export declare const OBSERVERS = "__observers__"; | ||
export declare type EventsArray = Array<any>; | ||
export declare type Observer = (data: any) => void; | ||
export declare type ObserversArray = Array<Observer>; | ||
export declare type EventsArray<T = any> = Array<T>; | ||
export declare type Observer<T = any> = (data: T | Array<T> | undefined) => void; | ||
export declare type ObserversArray<T = any> = Array<Observer<T>>; | ||
declare global { | ||
@@ -19,3 +19,3 @@ interface Window { | ||
} | ||
declare class Observable { | ||
export declare class Observable<T = any> { | ||
_namespace: string; | ||
@@ -29,8 +29,7 @@ private static initialize; | ||
set namespace(namespace: string); | ||
publish(data: any): void; | ||
dispatch: (data: any) => void; | ||
subscribe(observer: Observer, options?: SubscriptionOptions): void; | ||
unsubscribe(observer: Observer): void; | ||
publish(data: T): void; | ||
dispatch: (data: T) => void; | ||
subscribe(observer: Observer<T>, options?: SubscriptionOptions): void; | ||
unsubscribe(observer: Observer<T>): void; | ||
clear(): void; | ||
} | ||
export default Observable; |
@@ -24,3 +24,2 @@ 'use strict'; | ||
var OBSERVERS = '__observers__'; | ||
var Observable = /*#__PURE__*/function () { | ||
@@ -40,4 +39,9 @@ function Observable(namespace) { | ||
if (!window[SHARED][EVENTS]) window[SHARED][EVENTS] = {}; | ||
if (!window[SHARED][OBSERVERS]) window[SHARED][OBSERVERS] = {}; | ||
if (!window[SHARED][EVENTS]) { | ||
window[SHARED][EVENTS] = {}; | ||
} | ||
if (!window[SHARED][OBSERVERS]) { | ||
window[SHARED][OBSERVERS] = {}; | ||
} | ||
}; | ||
@@ -91,2 +95,7 @@ | ||
_proto.clear = function clear() { | ||
var _this$observers2; | ||
(_this$observers2 = this.observers) === null || _this$observers2 === void 0 ? void 0 : _this$observers2.forEach(function (observer) { | ||
return observer(undefined); | ||
}); | ||
this.events = []; | ||
@@ -109,4 +118,4 @@ this.observers = []; | ||
}, | ||
set: function set(listeners) { | ||
window[SHARED][OBSERVERS][this._namespace] = listeners; | ||
set: function set(observers) { | ||
window[SHARED][OBSERVERS][this._namespace] = observers; | ||
} | ||
@@ -125,3 +134,6 @@ }, { | ||
exports.EVENTS = EVENTS; | ||
exports.OBSERVERS = OBSERVERS; | ||
exports.Observable = Observable; | ||
exports.SHARED = SHARED; | ||
//# sourceMappingURL=windowed-observable.cjs.development.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e="__events__",t="__shared__",s="__observers__";exports.Observable=function(){function n(e){this.dispatch=this.publish,n.initialize(),this.namespace=e}n.initialize=function(){var n;window[t]||(window[t]=((n={})[e]={},n[s]={},n)),window[t][e]||(window[t][e]={}),window[t][s]||(window[t][s]={})};var i,r=n.prototype;return r.publish=function(e){var t;null===(t=this.observers)||void 0===t||t.forEach((function(t){return t(e)})),this.events.push(e)},r.subscribe=function(e,t){void 0===t&&(t={latest:!1,every:!1});var s=t.every,n=t.latest,i=this.events;(n||s)&&i.length>0&&(n&&e(i[i.length-1]),s&&e(i)),this.observers=this.observers.concat(e)},r.unsubscribe=function(e){this.observers=this.observers.filter((function(t){return t!==e}))},r.clear=function(){this.events=[],this.observers=[]},(i=[{key:"events",get:function(){return window[t][e][this._namespace]},set:function(s){window[t][e][this._namespace]=s}},{key:"observers",get:function(){return window[t][s][this._namespace]},set:function(e){window[t][s][this._namespace]=e}},{key:"namespace",set:function(e){this._namespace=e,this.events||(this.events=[]),this.observers||(this.observers=[])}}])&&function(e,t){for(var s=0;s<t.length;s++){var n=t[s];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}(n.prototype,i),n}(); | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e="__events__",t="__shared__",s="__observers__",n=function(){function n(e){this.dispatch=this.publish,n.initialize(),this.namespace=e}n.initialize=function(){var n;window[t]||(window[t]=((n={})[e]={},n[s]={},n)),window[t][e]||(window[t][e]={}),window[t][s]||(window[t][s]={})};var i,r=n.prototype;return r.publish=function(e){var t;null===(t=this.observers)||void 0===t||t.forEach((function(t){return t(e)})),this.events.push(e)},r.subscribe=function(e,t){void 0===t&&(t={latest:!1,every:!1});var s=t.every,n=t.latest,i=this.events;(n||s)&&i.length>0&&(n&&e(i[i.length-1]),s&&e(i)),this.observers=this.observers.concat(e)},r.unsubscribe=function(e){this.observers=this.observers.filter((function(t){return t!==e}))},r.clear=function(){var e;null===(e=this.observers)||void 0===e||e.forEach((function(e){return e(void 0)})),this.events=[],this.observers=[]},(i=[{key:"events",get:function(){return window[t][e][this._namespace]},set:function(s){window[t][e][this._namespace]=s}},{key:"observers",get:function(){return window[t][s][this._namespace]},set:function(e){window[t][s][this._namespace]=e}},{key:"namespace",set:function(e){this._namespace=e,this.events||(this.events=[]),this.observers||(this.observers=[])}}])&&function(e,t){for(var s=0;s<t.length;s++){var n=t[s];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}(n.prototype,i),n}();exports.EVENTS=e,exports.OBSERVERS=s,exports.Observable=n,exports.SHARED=t; | ||
//# sourceMappingURL=windowed-observable.cjs.production.min.js.map |
@@ -20,3 +20,2 @@ function _defineProperties(target, props) { | ||
var OBSERVERS = '__observers__'; | ||
var Observable = /*#__PURE__*/function () { | ||
@@ -36,4 +35,9 @@ function Observable(namespace) { | ||
if (!window[SHARED][EVENTS]) window[SHARED][EVENTS] = {}; | ||
if (!window[SHARED][OBSERVERS]) window[SHARED][OBSERVERS] = {}; | ||
if (!window[SHARED][EVENTS]) { | ||
window[SHARED][EVENTS] = {}; | ||
} | ||
if (!window[SHARED][OBSERVERS]) { | ||
window[SHARED][OBSERVERS] = {}; | ||
} | ||
}; | ||
@@ -87,2 +91,7 @@ | ||
_proto.clear = function clear() { | ||
var _this$observers2; | ||
(_this$observers2 = this.observers) === null || _this$observers2 === void 0 ? void 0 : _this$observers2.forEach(function (observer) { | ||
return observer(undefined); | ||
}); | ||
this.events = []; | ||
@@ -105,4 +114,4 @@ this.observers = []; | ||
}, | ||
set: function set(listeners) { | ||
window[SHARED][OBSERVERS][this._namespace] = listeners; | ||
set: function set(observers) { | ||
window[SHARED][OBSERVERS][this._namespace] = observers; | ||
} | ||
@@ -121,3 +130,3 @@ }, { | ||
export { Observable }; | ||
export { EVENTS, OBSERVERS, Observable, SHARED }; | ||
//# sourceMappingURL=windowed-observable.esm.js.map |
{ | ||
"name": "windowed-observable", | ||
"author": "Luis Takahashi", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"license": "MIT", | ||
@@ -17,8 +17,10 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"start": "tsdx watch", | ||
"start": "tsdx watch --noClean", | ||
"build": "tsdx build", | ||
"test": "tsdx test", | ||
"test:watch": "yarn test --watch", | ||
"test:ci": "yarn test --ci --coverage --maxWorkers=2", | ||
"lint": "tsdx lint", | ||
"prepare": "tsdx build", | ||
"validate": "npm-run-all --parallel lint test build" | ||
"validate": "npm-run-all --parallel lint test:ci build" | ||
}, | ||
@@ -33,3 +35,2 @@ "repository": { | ||
"homepage": "https://github.com/luistak/windowed-observable#readme", | ||
"peerDependencies": {}, | ||
"husky": { | ||
@@ -48,7 +49,7 @@ "hooks": { | ||
"husky": "^4.2.5", | ||
"npm-run-all": "^4.1.5", | ||
"tsdx": "^0.13.2", | ||
"tslib": "^2.0.0", | ||
"typescript": "^3.9.7", | ||
"npm-run-all": "^4.1.5" | ||
"typescript": "^3.9.7" | ||
} | ||
} |
@@ -1,7 +0,1 @@ | ||
export { | ||
Observer, | ||
ObserversArray, | ||
EventsArray, | ||
SubscriptionOptions, | ||
default as Observable, | ||
} from './observable'; | ||
export * from './observable'; |
@@ -5,5 +5,5 @@ export const EVENTS = '__events__'; | ||
export type EventsArray = Array<any>; | ||
export type Observer = (data: any) => void; | ||
export type ObserversArray = Array<Observer>; | ||
export type EventsArray<T = any> = Array<T>; | ||
export type Observer<T = any> = (data: T | Array<T> | undefined) => void; | ||
export type ObserversArray<T = any> = Array<Observer<T>>; | ||
@@ -24,3 +24,3 @@ declare global { | ||
class Observable { | ||
export class Observable<T = any> { | ||
_namespace!: string; | ||
@@ -35,5 +35,8 @@ | ||
} | ||
if (!window[SHARED][EVENTS]) window[SHARED][EVENTS] = {}; | ||
if (!window[SHARED][OBSERVERS]) window[SHARED][OBSERVERS] = {}; | ||
if (!window[SHARED][EVENTS]) { | ||
window[SHARED][EVENTS] = {}; | ||
} | ||
if (!window[SHARED][OBSERVERS]) { | ||
window[SHARED][OBSERVERS] = {}; | ||
} | ||
} | ||
@@ -47,16 +50,16 @@ | ||
private get events(): EventsArray { | ||
private get events(): EventsArray<T> { | ||
return window[SHARED][EVENTS][this._namespace]; | ||
} | ||
private get observers(): ObserversArray { | ||
private get observers(): ObserversArray<T> { | ||
return window[SHARED][OBSERVERS][this._namespace]; | ||
} | ||
private set events(events: EventsArray) { | ||
private set events(events: EventsArray<T>) { | ||
window[SHARED][EVENTS][this._namespace] = events; | ||
} | ||
private set observers(listeners: ObserversArray) { | ||
window[SHARED][OBSERVERS][this._namespace] = listeners; | ||
private set observers(observers: ObserversArray<T>) { | ||
window[SHARED][OBSERVERS][this._namespace] = observers; | ||
} | ||
@@ -71,4 +74,4 @@ | ||
publish(data: any): void { | ||
this.observers?.forEach((observer: Observer) => observer(data)); | ||
publish(data: T): void { | ||
this.observers?.forEach((observer: Observer<T>) => observer(data)); | ||
@@ -81,3 +84,3 @@ this.events.push(data); | ||
subscribe( | ||
observer: Observer, | ||
observer: Observer<T>, | ||
options: SubscriptionOptions = { latest: false, every: false } | ||
@@ -103,7 +106,9 @@ ): void { | ||
unsubscribe(observer: Observer) { | ||
this.observers = this.observers.filter(obs => obs !== observer); | ||
unsubscribe(observer: Observer<T>) { | ||
this.observers = this.observers.filter((obs) => obs !== observer); | ||
} | ||
clear() { | ||
this.observers?.forEach((observer: Observer<T>) => observer(undefined)); | ||
this.events = []; | ||
@@ -113,3 +118,1 @@ this.observers = []; | ||
} | ||
export default Observable; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
416
0
31676
14
1
0