bloc-react
Advanced tools
Comparing version 0.1.7 to 0.1.8
@@ -1,2 +0,2 @@ | ||
import { Subscription } from 'rxjs'; | ||
import { Observer, Subscription } from 'rxjs'; | ||
import { ReactElement } from 'react'; | ||
@@ -85,3 +85,3 @@ | ||
readonly addRemoveListener: (method: RemoveMethods) => () => void; | ||
subscribe: (next?: ((value: any) => void) | undefined) => Subscription; | ||
subscribe: (observer: Partial<Observer<any>>) => Subscription; | ||
complete: () => void; | ||
@@ -104,3 +104,3 @@ clearCache: () => void; | ||
id: string; | ||
createdAt: number; | ||
createdAt: Date; | ||
meta: BlocMeta; | ||
@@ -110,5 +110,4 @@ changeListeners: ChangeMethod[]; | ||
valueChangeListeners: ValueChangeMethod[]; | ||
consumer: BlocConsumer | null; | ||
constructor(initialValue: T, blocOptions?: BlocOptions); | ||
protected _consumer: BlocConsumer | null; | ||
set consumer(consumer: BlocConsumer); | ||
readonly removeChangeListener: (index: number) => void; | ||
@@ -115,0 +114,0 @@ readonly addChangeListener: (method: ChangeMethod) => () => void; |
@@ -31,3 +31,7 @@ 'use strict'; | ||
}; | ||
this.subscribe = (next) => this._subject.subscribe(next); | ||
this.subscribe = (observer) => this._subject.subscribe({ | ||
next: observer.next, | ||
complete: observer.complete, | ||
error: observer.error | ||
}); | ||
this.complete = () => { | ||
@@ -94,3 +98,3 @@ this.isClosed = true; | ||
this.id = nanoid.nanoid(); | ||
this.createdAt = Date.now(); | ||
this.createdAt = new Date(); | ||
this.meta = { | ||
@@ -102,3 +106,3 @@ scope: "unknown" | ||
this.valueChangeListeners = []; | ||
this._consumer = null; | ||
this.consumer = null; | ||
this.removeChangeListener = (index) => { | ||
@@ -129,3 +133,3 @@ this.changeListeners.splice(index, 1); | ||
this.notifyChange = (state) => { | ||
this._consumer?.notifyChange(this, state); | ||
this.consumer?.notifyChange(this, state); | ||
this.changeListeners.forEach((fn) => fn({ | ||
@@ -137,9 +141,6 @@ currentState: this.state, | ||
this.notifyValueChange = () => { | ||
this._consumer?.notifyValueChange(this); | ||
this.consumer?.notifyValueChange(this); | ||
this.valueChangeListeners.forEach((fn) => fn(this.state, this)); | ||
}; | ||
} | ||
set consumer(consumer) { | ||
this._consumer = consumer; | ||
} | ||
} | ||
@@ -164,3 +165,3 @@ | ||
this.notifyTransition = (state, event) => { | ||
this._consumer?.notifyTransition(this, state, event); | ||
this.consumer?.notifyTransition(this, state, event); | ||
this.onTransition?.({ | ||
@@ -399,4 +400,8 @@ currentState: this.state, | ||
if (subscribe) { | ||
const subscription = blocInstance.subscribe(updateData); | ||
return () => subscription.unsubscribe(); | ||
const subscription = blocInstance.subscribe({ | ||
next: updateData | ||
}); | ||
return () => { | ||
subscription.unsubscribe(); | ||
}; | ||
} | ||
@@ -403,0 +408,0 @@ }, []); |
{ | ||
"name": "bloc-react", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "main": "dist/bloc-react.js", |
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
355340
2261