Skip to content

Commit

Permalink
reused readSub
Browse files Browse the repository at this point in the history
  • Loading branch information
jessekelly881 committed Apr 21, 2024
1 parent ecebbe2 commit 820bf19
Showing 1 changed file with 16 additions and 27 deletions.
43 changes: 16 additions & 27 deletions packages/rx/src/Rx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,25 +662,29 @@ function makeStream<A, E>(
// constructors - subscription ref
// -----------------------------------------------------------------------------

const makeSubRef = (
refRx: Rx<SubscriptionRef.SubscriptionRef<any> | Result.Result<SubscriptionRef.SubscriptionRef<any>, any>>
) => {
function read(get: Context) {
const ref = get(refRx)
if (SubscriptionRef.SubscriptionRefTypeId in ref) {
/** @internal */
const readSub = (subRx: Rx<Subscribable.Subscribable<any, any> | Result.Result<Subscribable.Subscribable<any, any>, any>>) => (get: Context) => {

Check failure on line 666 in packages/rx/src/Rx.ts

View workflow job for this annotation

GitHub Actions / Lint

Require line break(s)

Check failure on line 666 in packages/rx/src/Rx.ts

View workflow job for this annotation

GitHub Actions / Lint

Require line break(s)
const sub = get(subRx)
if (Subscribable.TypeId in sub) {
get.addFinalizer(
ref.changes.pipe(
sub.changes.pipe(
Stream.runForEach((value) => get.setSelf(value)),
Effect.runCallback
)
)
return Effect.runSync(SubscriptionRef.get(ref))
} else if (ref._tag !== "Success") {
return ref
return Effect.runSync(sub.get)
} else if (sub._tag !== "Success") {
return sub
}
return makeStream(get, ref.value.changes, Result.initial(true))
return makeStream(get, sub.value.changes, Result.initial(true))
}


Check failure on line 682 in packages/rx/src/Rx.ts

View workflow job for this annotation

GitHub Actions / Lint

Extra line break(s)
const makeSubRef = (
refRx: Rx<SubscriptionRef.SubscriptionRef<any> | Result.Result<SubscriptionRef.SubscriptionRef<any>, any>>
) => {
const read = readSub(refRx);

Check failure on line 686 in packages/rx/src/Rx.ts

View workflow job for this annotation

GitHub Actions / Lint

Extra code ";"

function write(ctx: WriteContext<SubscriptionRef.SubscriptionRef<any>>, value: any) {
const ref = ctx.get(refRx)
if (SubscriptionRef.SubscriptionRefTypeId in ref) {
Expand Down Expand Up @@ -733,22 +737,7 @@ export const subRef: {
export const makeSub = (
subRx: Rx<Subscribable.Subscribable<any, any> | Result.Result<Subscribable.Subscribable<any, any>, any>>
) => {
function read(get: Context) {
const sub = get(subRx)
if (Subscribable.TypeId in sub) {
get.addFinalizer(
sub.changes.pipe(
Stream.runForEach((value) => get.setSelf(value)),
Effect.runCallback
)
)
return Effect.runSync(sub.get)
} else if (sub._tag !== "Success") {
return sub
}
return makeStream(get, sub.value.changes, Result.initial(true))
}

const read = readSub(subRx)
return readable(read)
}

Expand Down

0 comments on commit 820bf19

Please sign in to comment.