Comparing version 0.1.5 to 0.1.6
@@ -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;this.subscribe((function e(i){t.unsubscribe(e),s(i)}))})}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.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){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}; | ||
//# 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;this.subscribe((function i(e){t.unsubscribe(i),s(e)}))})}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}}function t(s){return s(this.val),this}function i(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}export{s as Cuprum,i as fromEvent,t as tap}; | ||
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}; | ||
//# sourceMappingURL=bundle.min.js.map |
@@ -1,3 +0,2 @@ | ||
export { Cuprum, tap, fromEvent }; | ||
declare class Cuprum<T> { | ||
export declare class Cuprum<T> { | ||
private val; | ||
@@ -22,6 +21,7 @@ private subscribers; | ||
} | ||
declare class Subscription { | ||
export declare class Subscription { | ||
unsubscribe: () => void; | ||
} | ||
declare function tap(fn: (val: any) => any): any; | ||
declare function fromEvent(element: any, eventType: any): Cuprum<Event>; | ||
export declare function tap(fn: (val: any) => any): any; | ||
export declare function fromEvent(element: any, eventType: any): Cuprum<Event>; | ||
export declare function combine<T, U>(obs1$: Cuprum<T>, obs2$: Cuprum<U>): Cuprum<[T, U]>; |
{ | ||
"name": "cuprum", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "Tiny state management library", | ||
@@ -5,0 +5,0 @@ "main": "dist/bundle.common.min.js", |
@@ -1,4 +0,2 @@ | ||
export { Cuprum, tap, fromEvent }; | ||
class Cuprum<T> { | ||
export class Cuprum<T> { | ||
private val: T; | ||
@@ -65,5 +63,4 @@ private subscribers: Set<(value: T) => void> = new Set(); | ||
return new Promise<T>((resolve) => { | ||
const self = this; | ||
this.subscribe(function fn(value) { | ||
self.unsubscribe(fn); | ||
const sub = this.subscribe(function fn(value) { | ||
sub.unsubscribe(); | ||
resolve(value); | ||
@@ -109,7 +106,7 @@ }); | ||
class Subscription { | ||
export class Subscription { | ||
unsubscribe: () => void; | ||
} | ||
function tap(fn: (val: any) => any) { | ||
export function tap(fn: (val: any) => any) { | ||
fn(this.val); | ||
@@ -119,3 +116,3 @@ return this; | ||
function fromEvent(element, eventType) { | ||
export function fromEvent(element, eventType) { | ||
const obs$ = new Cuprum<Event>(); | ||
@@ -136,3 +133,3 @@ const dispatch = (evt: Event) => { | ||
// TODO: combine with more than two arguments | ||
function combine<T, U>(obs1$: Cuprum<T>, obs2$: Cuprum<U>) { | ||
export function combine<T, U>(obs1$: Cuprum<T>, obs2$: Cuprum<U>) { | ||
const obs$ = new Cuprum<[T, U]>(); | ||
@@ -139,0 +136,0 @@ let sub1: Subscription; |
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
21256
173