Skip to content

Commit

Permalink
api cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Smart committed Sep 20, 2023
1 parent 5b2733f commit 7726b27
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 71 deletions.
5 changes: 5 additions & 0 deletions .changeset/slimy-moons-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect-rx/rx": patch
---

api cleanup
4 changes: 2 additions & 2 deletions docs/rx/Result.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ Added in v1.0.0
**Signature**
```ts
export declare const waiting: <E, A>(previous: Option.Option<Success<E, A> | Failure<E, A>>) => Waiting<E, A>
export declare const waiting: <E, A>(previous: Initial<E, A> | Success<E, A> | Failure<E, A>) => Waiting<E, A>
```
Added in v1.0.0
Expand Down Expand Up @@ -248,7 +248,7 @@ Added in v1.0.0
```ts
export interface Waiting<E, A> extends Result.Variance<E, A> {
readonly _tag: 'Waiting'
readonly previous: Option.Option<Success<E, A> | Failure<E, A>>
readonly previous: Initial<E, A> | Success<E, A> | Failure<E, A>
}
```

Expand Down
61 changes: 39 additions & 22 deletions docs/rx/Rx.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ Added in v1.0.0
- [Get (type alias)](#get-type-alias)
- [GetResult (type alias)](#getresult-type-alias)
- [Mount (type alias)](#mount-type-alias)
- [Read (type alias)](#read-type-alias)
- [Refresh (type alias)](#refresh-type-alias)
- [Set (type alias)](#set-type-alias)
- [Subscribe (type alias)](#subscribe-type-alias)
- [SubscribeGetter (type alias)](#subscribegetter-type-alias)
- [Write (type alias)](#write-type-alias)
- [RxResultFn (interface)](#rxresultfn-interface)
- [RxRuntime (interface)](#rxruntime-interface)
- [Writable (interface)](#writable-interface)
Expand Down Expand Up @@ -95,9 +97,9 @@ Added in v1.0.0
```ts
export declare const effect: {
<E, A>(create: (get: Rx.Get, ctx: Context) => Effect.Effect<never, E, A>): Rx<Result.Result<E, A>>
<E, A>(create: Rx.Read<Effect.Effect<never, E, A>>): Rx<Result.Result<E, A>>
<RR, R extends RR, E, A, RE>(
create: (get: Rx.Get, ctx: Context) => Effect.Effect<R, E, A>,
create: Rx.Read<Effect.Effect<R, E, A>>,
options: { readonly runtime: RxRuntime<RE, RR> }
): Rx<Result.Result<E | RE, A>>
}
Expand Down Expand Up @@ -136,10 +138,7 @@ Added in v1.0.0
**Signature**
```ts
export declare const readable: <A>(
read: (get: Rx.Get, ctx: Context) => A,
refresh?: (f: <A>(rx: Rx<A>) => void) => void
) => Rx<A>
export declare const readable: <A>(read: Rx.Read<A>, refresh?: (f: <A>(rx: Rx<A>) => void) => void) => Rx<A>
```
Added in v1.0.0
Expand All @@ -163,9 +162,9 @@ Added in v1.0.0
```ts
export declare const scoped: {
<E, A>(create: (get: Rx.Get, ctx: Context) => Effect.Effect<Scope.Scope, E, A>): Rx<Result.Result<E, A>>
<E, A>(create: Rx.Read<Effect.Effect<Scope.Scope, E, A>>): Rx<Result.Result<E, A>>
<RR, R extends RR | Scope.Scope, E, A, RE>(
create: (get: Rx.Get, ctx: Context) => Effect.Effect<R, E, A>,
create: Rx.Read<Effect.Effect<R, E, A>>,
options: { readonly runtime: RxRuntime<RE, RR> }
): Rx<Result.Result<E | RE, A>>
}
Expand Down Expand Up @@ -205,12 +204,10 @@ Added in v1.0.0
```ts
export declare const stream: {
<E, A>(create: (get: Rx.Get, ctx: Context) => Stream.Stream<never, E, A>): Rx<
Result.Result<E | NoSuchElementException, A>
>
<E, A>(create: Rx.Read<Stream.Stream<never, E, A>>): Rx<Result.Result<E | NoSuchElementException, A>>
<RR, R extends RR, E, A, RE>(
create: (get: Rx.Get, ctx: Context) => Stream.Stream<R, E, A>,
runtime: RxRuntime<RE, RR>
create: Rx.Read<Stream.Stream<R, E, A>>,
options: { readonly runtime: RxRuntime<RE, RR> }
): Rx<Result.Result<E | RE | NoSuchElementException, A>>
}
```
Expand All @@ -223,12 +220,12 @@ Added in v1.0.0
```ts
export declare const streamPull: {
<E, A>(
create: (get: Rx.Get, ctx: Context) => Stream.Stream<never, E, A>,
options?: { readonly disableAccumulation?: boolean }
): Writable<Result.Result<NoSuchElementException | E, A[]>, void>
<E, A>(create: Rx.Read<Stream.Stream<never, E, A>>, options?: { readonly disableAccumulation?: boolean }): Writable<
Result.Result<NoSuchElementException | E, A[]>,
void
>
<RR, R extends RR, E, A, RE>(
create: (get: Rx.Get, ctx: Context) => Stream.Stream<R, E, A>,
create: Rx.Read<Stream.Stream<R, E, A>>,
options: { readonly runtime: RxRuntime<RE, RR>; readonly disableAccumulation?: boolean | undefined }
): Writable<Result.Result<NoSuchElementException | E | RE, A[]>, void>
}
Expand All @@ -242,8 +239,8 @@ Added in v1.0.0
```ts
export declare const writable: <R, W>(
read: (get: Rx.Get, ctx: Context) => R,
write: (get: Rx.Get, set: Rx.Set, setSelf: (_: R) => void, value: W) => void,
read: Rx.Read<R>,
write: Rx.Write<R, W>,
refresh?: (f: <A>(rx: Rx<A>) => void) => void
) => Writable<R, W>
```
Expand Down Expand Up @@ -301,7 +298,7 @@ Added in v1.0.0
export interface Rx<A> extends Pipeable, Inspectable.Inspectable {
readonly [TypeId]: TypeId
readonly keepAlive: boolean
readonly read: (get: Rx.Get, ctx: Context) => A
readonly read: Rx.Read<A>
readonly refresh: (f: <A>(rx: Rx<A>) => void) => void
readonly label?: readonly [name: string, stack: string]
}
Expand Down Expand Up @@ -343,6 +340,16 @@ export type Mount = <A>(rx: Rx<A>) => () => void
Added in v1.0.0
### Read (type alias)
**Signature**
```ts
export type Read<A> = (get: Rx.Get, ctx: Context) => A
```
Added in v1.0.0
### Refresh (type alias)
**Signature**
Expand Down Expand Up @@ -389,6 +396,16 @@ export type SubscribeGetter = <A>(rx: Rx<A>, f: () => void) => readonly [get: ()
Added in v1.0.0
### Write (type alias)
**Signature**
```ts
export type Write<R, W> = (get: Rx.Get, set: Rx.Set, setSelf: (_: R) => void, refreshSelf: () => void, value: W) => void
```
Added in v1.0.0
## RxResultFn (interface)
**Signature**
Expand Down Expand Up @@ -416,7 +433,7 @@ Added in v1.0.0
```ts
export interface Writable<R, W> extends Rx<R> {
readonly [WritableTypeId]: WritableTypeId
readonly write: (get: Rx.Get, set: Rx.Set, setSelf: (_: R) => void, value: W) => void
readonly write: (get: Rx.Get, set: Rx.Set, setSelf: (_: R) => void, refreshSelf: () => void, value: W) => void
}
```

Expand Down
13 changes: 6 additions & 7 deletions packages/rx/src/Result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,16 @@ export const fromExit = <E, A>(exit: Exit.Exit<E, A>): Success<E, A> | Failure<E
*/
export const waitingFrom = <E, A>(previous: Option.Option<Result<E, A>>): Waiting<E, A> => {
if (previous._tag === "None") {
return waiting(Option.none())
return waiting(constInitial)
}

switch (previous.value._tag) {
case "Initial":
return waiting(Option.none())
case "Waiting":
return previous.value
case "Initial":
case "Success":
case "Failure":
return waiting(Option.some(previous.value))
return waiting(previous.value)
}
}

Expand All @@ -111,7 +110,7 @@ const constInitial: Initial<never, never> = Object.assign(Object.create(ResultPr
*/
export interface Waiting<E, A> extends Result.Variance<E, A> {
readonly _tag: "Waiting"
readonly previous: Option.Option<Success<E, A> | Failure<E, A>>
readonly previous: Initial<E, A> | Success<E, A> | Failure<E, A>
}

/**
Expand All @@ -124,7 +123,7 @@ export const isWaiting = <E, A>(result: Result<E, A>): result is Waiting<E, A> =
* @since 1.0.0
* @category constructors
*/
export const waiting = <E, A>(previous: Option.Option<Success<E, A> | Failure<E, A>>): Waiting<E, A> => {
export const waiting = <E, A>(previous: Initial<E, A> | Success<E, A> | Failure<E, A>): Waiting<E, A> => {
const result = Object.create(ResultProto)
result._tag = "Waiting"
result.previous = previous
Expand Down Expand Up @@ -200,7 +199,7 @@ export const noWaiting = <E, A>(result: Result<E, A>): NoWaiting<E, A> => {
case "Failure":
return result
case "Waiting":
return result.previous._tag === "None" ? constInitial : result.previous.value
return result.previous
}
}

Expand Down
Loading

0 comments on commit 7726b27

Please sign in to comment.