diff --git a/.changeset/few-cooks-tap.md b/.changeset/few-cooks-tap.md
new file mode 100644
index 0000000..ebc881d
--- /dev/null
+++ b/.changeset/few-cooks-tap.md
@@ -0,0 +1,6 @@
+---
+"@effect-rx/rx-react": patch
+"@effect-rx/rx": patch
+---
+
+fix react store & remove some apis
diff --git a/packages/rx-react/src/index.ts b/packages/rx-react/src/index.ts
index 0c2f9c1..163979a 100644
--- a/packages/rx-react/src/index.ts
+++ b/packages/rx-react/src/index.ts
@@ -20,17 +20,19 @@ class RxStore {
readonly registry: Registry.Registry,
readonly rx: Rx.Rx
) {}
-
- value!: A
-
+ value = this.registry.get(this.rx)
+ init = false
subscribe = (f: () => void): () => void => {
- this.value = this.registry.get(this.rx)
+ if (this.init === true) {
+ this.value = this.registry.get(this.rx)
+ } else {
+ this.init = true
+ }
return this.registry.subscribe(this.rx, (a) => {
this.value = a
f()
})
}
-
snapshot = (): A => this.value
}
diff --git a/packages/rx/src/Registry.ts b/packages/rx/src/Registry.ts
index 69a8dac..7f3f4e0 100644
--- a/packages/rx/src/Registry.ts
+++ b/packages/rx/src/Registry.ts
@@ -27,8 +27,6 @@ export interface Registry {
readonly refresh: Rx.Rx.Refresh
readonly set: Rx.Rx.Set
readonly subscribe: Rx.Rx.Subscribe
- readonly subscribeWithPrevious: Rx.Rx.SubscribeWithPrevious
- readonly queue: Rx.Rx.Queue
}
/**
diff --git a/packages/rx/src/Rx.ts b/packages/rx/src/Rx.ts
index e6f3bf6..f7c850a 100644
--- a/packages/rx/src/Rx.ts
+++ b/packages/rx/src/Rx.ts
@@ -151,10 +151,6 @@ export interface Context {
readonly subscribe: (rx: Rx, f: (_: A) => void, options?: {
readonly immediate?: boolean
}) => void
- readonly subscribeWithPrevious: (rx: Rx, f: (prev: Option.Option, value: A) => void, options?: {
- readonly immediate?: boolean
- }) => void
- readonly queue: (rx: Rx) => Effect.Effect>
}
/**
diff --git a/packages/rx/src/internal/registry.ts b/packages/rx/src/internal/registry.ts
index 53184ef..6cfb0b6 100644
--- a/packages/rx/src/internal/registry.ts
+++ b/packages/rx/src/internal/registry.ts
@@ -2,10 +2,6 @@ import type * as Registry from "@effect-rx/rx/Registry"
import type * as Rx from "@effect-rx/rx/Rx"
import * as Equal from "@effect/data/Equal"
import * as Option from "@effect/data/Option"
-import * as Effect from "@effect/io/Effect"
-import * as Exit from "@effect/io/Exit"
-import * as Queue from "@effect/io/Queue"
-import * as Scope from "@effect/io/Scope"
const constImmediate = { immediate: true }
function constListener(_: any) {}
@@ -63,40 +59,10 @@ class RegistryImpl implements Registry.Registry {
}
}
- subscribeWithPrevious: Rx.Rx.SubscribeWithPrevious = (
- rx: Rx.Rx,
- f: (prev: Option.Option, value: A) => void,
- options?: { readonly immediate?: boolean }
- ): () => void => {
- let prev = Option.none()
- function listener(a: A) {
- const old = prev
- prev = Option.some(a)
- f(old, a)
- }
- return this.subscribe(rx, listener, options)
- }
-
mount(rx: Rx.Rx) {
return this.subscribe(rx, constListener, constImmediate)
}
- queue(rx: Rx.Rx) {
- return Effect.tap(Queue.unbounded(), (queue) => {
- const offer = Effect.async(() => {
- const cancel = this.subscribe(rx, (a) => {
- Queue.unsafeOffer(queue, a)
- }, constImmediate)
- return Effect.sync(cancel)
- })
- const shutdown = Queue.shutdown(queue)
- return Effect.zipRight(
- Effect.addFinalizer(() => shutdown),
- Effect.forkScoped(offer)
- )
- })
- }
-
ensureNode(rx: Rx.Rx): Node {
let node = this.nodes.get(rx)
if (node === undefined) {
@@ -358,24 +324,12 @@ class Lifetime implements Rx.Context {
this.node.invalidate()
}
- queue(rx: Rx.Rx): Effect.Effect> {
- const scope = Effect.runSync(Scope.make())
- this.addFinalizer(() => Effect.runFork(Scope.close(scope, Exit.unit)))
- return Effect.provideService(this.node.registry.queue(rx), Scope.Scope, scope)
- }
-
subscribe(rx: Rx.Rx, f: (_: A) => void, options?: {
readonly immediate?: boolean
}): void {
this.addFinalizer(this.node.registry.subscribe(rx, f, options))
}
- subscribeWithPrevious(rx: Rx.Rx, f: (prev: Option.Option, value: A) => void, options?: {
- readonly immediate?: boolean
- }): void {
- this.addFinalizer(this.node.registry.subscribeWithPrevious(rx, f, options))
- }
-
setSelf(a: A): void {
this.node.setValue(a)
}