Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed May 7, 2024
1 parent b7ae4d5 commit c81fd15
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .changeset/witty-buckets-kiss.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"@effect-rx/rx": patch
---

added Rx.sub for working with Subscribables
added Rx.subscribable for working with Subscribables
24 changes: 12 additions & 12 deletions packages/rx/src/Rx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ const RxRuntimeProto = {
return makeStreamPull(pullRx as any, options)
},

subRef(this: RxRuntime<any, any>, arg: any) {
subscriptionRef(this: RxRuntime<any, any>, arg: any) {
return makeSubRef(readable((get) => {
const previous = get.self<Result.Result<any, any>>()
const runtimeResult = get(this)
Expand All @@ -316,8 +316,8 @@ const RxRuntimeProto = {
}))
},

sub(this: RxRuntime<any, any>, arg: any) {
return makeSub(readable((get) => {
subscribable(this: RxRuntime<any, any>, arg: any) {
return makeSubscribable(readable((get) => {
const previous = get.self<Result.Result<any, any>>()
const runtimeResult = get(this)
if (runtimeResult._tag !== "Success") {
Expand Down Expand Up @@ -564,13 +564,13 @@ export interface RxRuntime<R, ER> extends Rx<Result.Result<Runtime.Runtime<R>, E
readonly initialValue?: ReadonlyArray<A>
}) => Writable<PullResult<A, E | ER>, void>

readonly subRef: <A, E>(
readonly subscriptionRef: <A, E>(
create:
| Effect.Effect<SubscriptionRef.SubscriptionRef<A>, E, R>
| Rx.Read<Effect.Effect<SubscriptionRef.SubscriptionRef<A>, E, R>>
) => Writable<Result.Result<A, E>, A>

readonly sub: <A, E, E1 = never>(
readonly subscribable: <A, E, E1 = never>(
create:
| Effect.Effect<Subscribable.Subscribable<A, E, R>, E1, R>
| Rx.Read<Effect.Effect<Subscribable.Subscribable<A, E, R>, E1, R>>
Expand Down Expand Up @@ -679,7 +679,7 @@ function makeStream<A, E>(
// -----------------------------------------------------------------------------

/** @internal */
const readSub =
const readSubscribable =
(subRx: Rx<Subscribable.Subscribable<any, any> | Result.Result<Subscribable.Subscribable<any, any>, any>>) =>
(get: Context) => {
const sub = get(subRx)
Expand Down Expand Up @@ -709,14 +709,14 @@ const makeSubRef = (
}
}

return writable(readSub(refRx), write)
return writable(readSubscribable(refRx), write)
}

/**
* @since 1.0.0
* @category constructors
*/
export const subRef: {
export const subscriptionRef: {
<A>(ref: SubscriptionRef.SubscriptionRef<A> | Rx.Read<SubscriptionRef.SubscriptionRef<A>>): Writable<A, A>
<A, E>(
effect:
Expand Down Expand Up @@ -749,15 +749,15 @@ export const subRef: {
* @since 1.0.0
* @category constructors
*/
export const makeSub = (
export const makeSubscribable = (
subRx: Rx<Subscribable.Subscribable<any, any> | Result.Result<Subscribable.Subscribable<any, any>, any>>
) => readable(readSub(subRx))
) => readable(readSubscribable(subRx))

/**
* @since 1.0.0
* @category constructors
*/
export const sub: {
export const subscribable: {
<A, E>(ref: Subscribable.Subscribable<A, E> | Rx.Read<Subscribable.Subscribable<A, E>>): Rx<A>
<A, E, E1>(
effect:
Expand All @@ -771,7 +771,7 @@ export const sub: {
| Effect.Effect<Subscribable.Subscribable<any, any>, any, never>
| Rx.Read<Effect.Effect<Subscribable.Subscribable<any, any>, any, never>>
) =>
makeSub(readable((get) => {
makeSubscribable(readable((get) => {
let value: Subscribable.Subscribable<any, any> | Effect.Effect<Subscribable.Subscribable<any, any>, any, any>
if (typeof ref === "function") {
value = ref(get)
Expand Down
10 changes: 5 additions & 5 deletions packages/rx/test/Rx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ describe("Rx", () => {
it("Subscribable", async () => {
vitest.useRealTimers()
const sub = Subscribable.make({ get: Effect.succeed(123), changes: Stream.empty })
const rx = Rx.sub(sub)
const rx = Rx.subscribable(sub)
const r = Registry.make()
const unmount = r.mount(rx)
assert.deepStrictEqual(r.get(rx), 123)
Expand All @@ -788,7 +788,7 @@ describe("Rx", () => {
it("Subscribable/SubscriptionRef", async () => {
vitest.useRealTimers()
const ref = SubscriptionRef.make(123).pipe(Effect.runSync)
const rx = Rx.sub(ref)
const rx = Rx.subscribable(ref)
const r = Registry.make()
assert.deepStrictEqual(r.get(rx), 123)
await Effect.runPromise(SubscriptionRef.update(ref, (a) => a + 1))
Expand All @@ -798,7 +798,7 @@ describe("Rx", () => {
it("SubscriptionRef", async () => {
vitest.useRealTimers()
const ref = SubscriptionRef.make(0).pipe(Effect.runSync)
const rx = Rx.subRef(ref)
const rx = Rx.subscriptionRef(ref)
const r = Registry.make()
const unmount = r.mount(rx)
assert.deepStrictEqual(r.get(rx), 0)
Expand All @@ -809,7 +809,7 @@ describe("Rx", () => {
})

it("SubscriptionRef/effect", async () => {
const rx = Rx.subRef(SubscriptionRef.make(0))
const rx = Rx.subscriptionRef(SubscriptionRef.make(0))
const r = Registry.make()
const unmount = r.mount(rx)
assert.deepStrictEqual(r.get(rx), Result.success(0, true))
Expand All @@ -820,7 +820,7 @@ describe("Rx", () => {
})

it("SubscriptionRef/runtime", async () => {
const rx = counterRuntime.subRef(SubscriptionRef.make(0))
const rx = counterRuntime.subscriptionRef(SubscriptionRef.make(0))
const r = Registry.make()
const unmount = r.mount(rx)
assert.deepStrictEqual(r.get(rx), Result.success(0, true))
Expand Down

0 comments on commit c81fd15

Please sign in to comment.