Comparing version 0.1.6 to 0.1.8
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});class s{constructor(){this.subscribers=new Set,this.subscribersHot=new Set,this.dispatched=!1,this.hot=!1}dispatch(s){this.val=s,this.dispatched=!0,this.subscribers.forEach(t=>t(s))}subscribeNext(s){return this.subscribers.add(s),this.notifyHotSubscribers(),{unsubscribe:()=>{this.subscribers.delete(s)}}}subscribe(s){return this.dispatched&&s(this.val),this.subscribeNext(s)}unsubscribe(s){this.subscribers.delete(s),this.notifyHotSubscribers()}notifyHotSubscribers(){this.subscribers.size>0!=this.hot&&(this.hot=this.subscribers.size>0,this.subscribersHot.forEach(s=>s(this.hot)))}subscribeHot(s){return this.subscribersHot.add(s),{unsubscribe:()=>{this.subscribersHot.delete(s)}}}clear(){this.subscribers.clear(),this.subscribersHot.clear()}value(){return this.val}promise(){return new Promise(s=>{const t=this.subscribe((function(e){t.unsubscribe(),s(e)}))})}map(t){const e=new s,i=s=>{e.dispatch(t(s))};return e.subscribeHot(s=>{s?this.subscribe(i):this.unsubscribe(i)}),e}filter(t){const e=new s,i=s=>{t(s)&&e.dispatch(s)};return e.subscribeHot(s=>{s?this.subscribe(i):this.unsubscribe(i)}),e}}exports.Cuprum=s,exports.Subscription=class{},exports.combine=function(t,e){const i=new s;let r,b;return i.subscribeHot(s=>{s?(r=t.subscribe(s=>{i.dispatch([s,e.value()])}),b=e.subscribe(s=>{i.dispatch([t.value(),s])})):(r.unsubscribe(),b.unsubscribe())}),i},exports.fromEvent=function(t,e){const i=new s,r=s=>{i.dispatch(s)};return i.subscribeHot(s=>{s?t.addEventListener(e,r,!1):t.removeEventListener(e,r,!1)}),i},exports.tap=function(s){return s(this.val),this}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});class s{constructor(){this.subscribers=new Set,this.subscribersHot=new Set,this.dispatched=!1,this.hot=!1}dispatch(s){const t=this.val;this.val=s,this.dispatched=!0,this.subscribers.forEach(e=>e(s,t))}subscribeNext(s){return this.subscribers.add(s),this.notifyHotSubscribers(),{unsubscribe:()=>{this.subscribers.delete(s)}}}subscribe(s){return this.dispatched&&s(this.val),this.subscribeNext(s)}unsubscribe(s){this.subscribers.delete(s),this.notifyHotSubscribers()}notifyHotSubscribers(){this.subscribers.size>0!=this.hot&&(this.hot=this.subscribers.size>0,this.subscribersHot.forEach(s=>s(this.hot)))}subscribeHot(s){return this.subscribersHot.add(s),{unsubscribe:()=>{this.subscribersHot.delete(s)}}}clear(){this.subscribers.clear(),this.subscribersHot.clear()}value(){return this.val}promise(){return new Promise(s=>{const t=this.subscribe((function(e){t.unsubscribe(),s(e)}))})}map(t){const e=new s,i=s=>{e.dispatch(t(s))};return e.subscribeHot(s=>{s?this.subscribe(i):this.unsubscribe(i)}),e}filter(t){const e=new s,i=s=>{t(s)&&e.dispatch(s)};return e.subscribeHot(s=>{s?this.subscribe(i):this.unsubscribe(i)}),e}}exports.Cuprum=s,exports.Subscription=class{},exports.combine=function(t,e){const i=new s;let r,b;return i.subscribeHot(s=>{s?(r=t.subscribe(s=>{i.dispatch([s,e.value()])}),b=e.subscribe(s=>{i.dispatch([t.value(),s])})):(r.unsubscribe(),b.unsubscribe())}),i},exports.fromEvent=function(t,e){const i=new s,r=s=>{i.dispatch(s)};return i.subscribeHot(s=>{s?t.addEventListener(e,r,!1):t.removeEventListener(e,r,!1)}),i},exports.tap=function(s){return s(this.val),this}; | ||
//# sourceMappingURL=bundle.common.min.js.map |
@@ -1,2 +0,2 @@ | ||
class s{constructor(){this.subscribers=new Set,this.subscribersHot=new Set,this.dispatched=!1,this.hot=!1}dispatch(s){this.val=s,this.dispatched=!0,this.subscribers.forEach(t=>t(s))}subscribeNext(s){return this.subscribers.add(s),this.notifyHotSubscribers(),{unsubscribe:()=>{this.subscribers.delete(s)}}}subscribe(s){return this.dispatched&&s(this.val),this.subscribeNext(s)}unsubscribe(s){this.subscribers.delete(s),this.notifyHotSubscribers()}notifyHotSubscribers(){this.subscribers.size>0!=this.hot&&(this.hot=this.subscribers.size>0,this.subscribersHot.forEach(s=>s(this.hot)))}subscribeHot(s){return this.subscribersHot.add(s),{unsubscribe:()=>{this.subscribersHot.delete(s)}}}clear(){this.subscribers.clear(),this.subscribersHot.clear()}value(){return this.val}promise(){return new Promise(s=>{const t=this.subscribe((function(i){t.unsubscribe(),s(i)}))})}map(t){const i=new s,e=s=>{i.dispatch(t(s))};return i.subscribeHot(s=>{s?this.subscribe(e):this.unsubscribe(e)}),i}filter(t){const i=new s,e=s=>{t(s)&&i.dispatch(s)};return i.subscribeHot(s=>{s?this.subscribe(e):this.unsubscribe(e)}),i}}class t{}function i(s){return s(this.val),this}function e(t,i){const e=new s,r=s=>{e.dispatch(s)};return e.subscribeHot(s=>{s?t.addEventListener(i,r,!1):t.removeEventListener(i,r,!1)}),e}function r(t,i){const e=new s;let r,b;return e.subscribeHot(s=>{s?(r=t.subscribe(s=>{e.dispatch([s,i.value()])}),b=i.subscribe(s=>{e.dispatch([t.value(),s])})):(r.unsubscribe(),b.unsubscribe())}),e}export{s as Cuprum,t as Subscription,r as combine,e as fromEvent,i as tap}; | ||
class s{constructor(){this.subscribers=new Set,this.subscribersHot=new Set,this.dispatched=!1,this.hot=!1}dispatch(s){const t=this.val;this.val=s,this.dispatched=!0,this.subscribers.forEach(i=>i(s,t))}subscribeNext(s){return this.subscribers.add(s),this.notifyHotSubscribers(),{unsubscribe:()=>{this.subscribers.delete(s)}}}subscribe(s){return this.dispatched&&s(this.val),this.subscribeNext(s)}unsubscribe(s){this.subscribers.delete(s),this.notifyHotSubscribers()}notifyHotSubscribers(){this.subscribers.size>0!=this.hot&&(this.hot=this.subscribers.size>0,this.subscribersHot.forEach(s=>s(this.hot)))}subscribeHot(s){return this.subscribersHot.add(s),{unsubscribe:()=>{this.subscribersHot.delete(s)}}}clear(){this.subscribers.clear(),this.subscribersHot.clear()}value(){return this.val}promise(){return new Promise(s=>{const t=this.subscribe((function(i){t.unsubscribe(),s(i)}))})}map(t){const i=new s,e=s=>{i.dispatch(t(s))};return i.subscribeHot(s=>{s?this.subscribe(e):this.unsubscribe(e)}),i}filter(t){const i=new s,e=s=>{t(s)&&i.dispatch(s)};return i.subscribeHot(s=>{s?this.subscribe(e):this.unsubscribe(e)}),i}}class t{}function i(s){return s(this.val),this}function e(t,i){const e=new s,r=s=>{e.dispatch(s)};return e.subscribeHot(s=>{s?t.addEventListener(i,r,!1):t.removeEventListener(i,r,!1)}),e}function r(t,i){const e=new s;let r,b;return e.subscribeHot(s=>{s?(r=t.subscribe(s=>{e.dispatch([s,i.value()])}),b=i.subscribe(s=>{e.dispatch([t.value(),s])})):(r.unsubscribe(),b.unsubscribe())}),e}export{s as Cuprum,t as Subscription,r as combine,e as fromEvent,i as tap}; | ||
//# sourceMappingURL=bundle.min.js.map |
@@ -9,4 +9,4 @@ export declare class Cuprum<T> { | ||
subscribeNext(fn: (value: T) => void): Subscription; | ||
subscribe(fn: (value: T) => void): Subscription; | ||
unsubscribe(fn: (value: T) => void): void; | ||
subscribe(fn: (value: T, oldValue?: T) => void): Subscription; | ||
unsubscribe(fn: (value: T, oldValue?: T) => void): void; | ||
private notifyHotSubscribers; | ||
@@ -13,0 +13,0 @@ subscribeHot(fn: (value: boolean) => void): { |
131
package.json
{ | ||
"name": "cuprum", | ||
"version": "0.1.6", | ||
"description": "Tiny state management library", | ||
"main": "dist/bundle.common.min.js", | ||
"module": "dist/bundle.min.js", | ||
"types": "dist/cuprum.d.ts", | ||
"sideEffects": false, | ||
"scripts": { | ||
"start": "http-server -o demo/ --silent", | ||
"build": "rollup --config --sourcemap", | ||
"dev": "rollup --config --sourcemap --watch", | ||
"test": "karma start", | ||
"lint": "npx eslint . --ext .js,.ts" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/edwinm/cuprum.git" | ||
}, | ||
"files": [ | ||
"src/cuprum.ts", | ||
"dist/cuprum.d.ts", | ||
"dist/bundle.min.js", | ||
"dist/bundle.min.js.map", | ||
"dist/bundle.common.min.js", | ||
"dist/bundle.common.min.js.map" | ||
], | ||
"author": { | ||
"name": "Edwin Martin", | ||
"email": "edwin@bitstorm.org", | ||
"url": "https://bitstorm.org/" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/edwinm/cuprum/issues" | ||
}, | ||
"homepage": "https://github.com/edwinm/cuprum#readme", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@types/mocha": "^7.0.2", | ||
"@types/node": "^14.0.4", | ||
"@typescript-eslint/eslint-plugin": "^3.0.2", | ||
"@typescript-eslint/parser": "^3.0.2", | ||
"eslint": "^7.1.0", | ||
"eslint-config-prettier": "^6.11.0", | ||
"http-server": "^0.12.3", | ||
"husky": "^4.2.5", | ||
"karma": "^5.0.9", | ||
"karma-chai": "^0.1.0", | ||
"karma-chrome-launcher": "^3.1.0", | ||
"karma-coverage": "^2.0.2", | ||
"karma-mocha": "^2.0.1", | ||
"karma-typescript": "^5.0.3", | ||
"mocha": "^7.2.0", | ||
"prettier": "^2.0.5", | ||
"pretty-quick": "^2.0.1", | ||
"rollup": "^2.10.2", | ||
"rollup-plugin-terser": "^5.3.0", | ||
"rollup-plugin-typescript2": "^0.27.1", | ||
"tslib": "^2.0.0", | ||
"typescript": "^3.9.2" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "pretty-quick --staged" | ||
"name": "cuprum", | ||
"version": "0.1.8", | ||
"description": "Tiny state management library", | ||
"main": "dist/bundle.common.min.js", | ||
"module": "dist/bundle.min.js", | ||
"types": "dist/cuprum.d.ts", | ||
"sideEffects": false, | ||
"scripts": { | ||
"start": "http-server -o demo/ --silent", | ||
"build": "rollup --config --sourcemap", | ||
"dev": "rollup --config --sourcemap --watch", | ||
"release": "npm i --package-lock && npm test && npm run build && npm publish", | ||
"test": "karma start", | ||
"lint": "npx eslint . --ext .js,.ts" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/edwinm/cuprum.git" | ||
}, | ||
"files": [ | ||
"src/cuprum.ts", | ||
"dist/cuprum.d.ts", | ||
"dist/bundle.min.js", | ||
"dist/bundle.min.js.map", | ||
"dist/bundle.common.min.js", | ||
"dist/bundle.common.min.js.map" | ||
], | ||
"author": { | ||
"name": "Edwin Martin", | ||
"email": "edwin@bitstorm.org", | ||
"url": "https://bitstorm.org/" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/edwinm/cuprum/issues" | ||
}, | ||
"homepage": "https://github.com/edwinm/cuprum#readme", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@types/mocha": "^7.0.2", | ||
"@types/node": "^14.0.4", | ||
"@typescript-eslint/eslint-plugin": "^3.0.2", | ||
"@typescript-eslint/parser": "^3.0.2", | ||
"eslint": "^7.1.0", | ||
"eslint-config-prettier": "^6.11.0", | ||
"http-server": "^0.12.3", | ||
"husky": "^4.2.5", | ||
"karma": "^5.0.9", | ||
"karma-chai": "^0.1.0", | ||
"karma-chrome-launcher": "^3.1.0", | ||
"karma-coverage": "^2.0.2", | ||
"karma-mocha": "^2.0.1", | ||
"karma-typescript": "^5.0.3", | ||
"mocha": "^7.2.0", | ||
"prettier": "^2.0.5", | ||
"pretty-quick": "^2.0.1", | ||
"rollup": "^2.10.2", | ||
"rollup-plugin-terser": "^5.3.0", | ||
"rollup-plugin-typescript2": "^0.27.1", | ||
"tslib": "^2.0.0", | ||
"typescript": "^3.9.2" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "pretty-quick --staged" | ||
} | ||
} | ||
} | ||
} |
export class Cuprum<T> { | ||
private val: T; | ||
private subscribers: Set<(value: T) => void> = new Set(); | ||
private subscribers: Set<(value: T, oldValue?: T) => void> = new Set(); | ||
private subscribersHot: Set<(value: boolean) => void> = new Set(); | ||
@@ -9,5 +9,6 @@ private dispatched = false; | ||
dispatch(value: T) { | ||
const oldValue = this.val; | ||
this.val = value; | ||
this.dispatched = true; | ||
this.subscribers.forEach((fn) => fn(value)); | ||
this.subscribers.forEach((fn) => fn(value, oldValue)); | ||
} | ||
@@ -25,3 +26,3 @@ | ||
subscribe(fn: (value: T) => void) { | ||
subscribe(fn: (value: T, oldValue?: T) => void) { | ||
if (this.dispatched) { | ||
@@ -33,3 +34,3 @@ fn(this.val); | ||
unsubscribe(fn: (value: T) => void) { | ||
unsubscribe(fn: (value: T, oldValue?: T) => void) { | ||
this.subscribers.delete(fn); | ||
@@ -117,2 +118,3 @@ this.notifyHotSubscribers(); | ||
// TODO: 1st arg is string, then doc.querySelectAll | ||
export function fromEvent(element, eventType) { | ||
@@ -119,0 +121,0 @@ const obs$ = new Cuprum<Event>(); |
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
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
22128
176