Add Effect v4 support, Fast Refresh tooling, and revamped docs #56
@@ -53,7 +53,7 @@ extends Pipeable.Class implements Query<K, A, E, R> {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
readonly context: Context.Context<Scope.Scope | QueryClient.QueryClient | R>,
|
readonly context: Context.Context<Scope.Scope | QueryClient.QueryClient | R>,
|
||||||
readonly key: Lens.Lens<K>,
|
readonly key: Subscribable.Subscribable<K>,
|
||||||
readonly keyEquivalence: Equivalence.Equivalence<K>,
|
readonly keyEquivalence: Equivalence.Equivalence<K>,
|
||||||
readonly f: (key: K) => Effect.Effect<A, E, R>,
|
readonly f: (key: K) => Effect.Effect<A, E, R>,
|
||||||
|
|
||||||
@@ -71,15 +71,23 @@ extends Pipeable.Class implements Query<K, A, E, R> {
|
|||||||
|
|
||||||
get run(): Effect.Effect<void> {
|
get run(): Effect.Effect<void> {
|
||||||
return Effect.all([
|
return Effect.all([
|
||||||
Stream.runFoldEffect(
|
Stream.runForEach(
|
||||||
this.key.changes,
|
this.key.changes,
|
||||||
() => Option.none<K>(),
|
key => Effect.gen({ self: this }, function*() {
|
||||||
(previous, key) => Effect.as(
|
yield* this.interrupt
|
||||||
Option.isSome(previous) && this.keyEquivalence(key, previous.value)
|
const latestFinalState = yield* Lens.get(this.latestFinalState)
|
||||||
? this.refreshSubscribable
|
|
||||||
: this.fetchSubscribable(key),
|
const state = yield* this.startCached(
|
||||||
Option.some(key),
|
Option.isSome(latestFinalState) && this.keyEquivalence(key, latestFinalState.value.key)
|
||||||
),
|
? latestFinalState.value
|
||||||
|
: {
|
||||||
|
key,
|
||||||
|
result: AsyncResult.initial(false),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
yield* Effect.forkScoped(this.watch(state))
|
||||||
|
}),
|
||||||
),
|
),
|
||||||
|
|
||||||
Effect.promise(() => import("@effect/platform-browser")).pipe(
|
Effect.promise(() => import("@effect/platform-browser")).pipe(
|
||||||
@@ -109,8 +117,6 @@ extends Pipeable.Class implements Query<K, A, E, R> {
|
|||||||
fetch(key: K): Effect.Effect<FinalQueryState<K, A, E>, Cause.NoSuchElementError> {
|
fetch(key: K): Effect.Effect<FinalQueryState<K, A, E>, Cause.NoSuchElementError> {
|
||||||
return Effect.gen({ self: this }, function*() {
|
return Effect.gen({ self: this }, function*() {
|
||||||
yield* this.interrupt
|
yield* this.interrupt
|
||||||
yield* Lens.set(this.key, key)
|
|
||||||
|
|
||||||
const state = yield* this.startCached({
|
const state = yield* this.startCached({
|
||||||
key,
|
key,
|
||||||
result: AsyncResult.initial(false),
|
result: AsyncResult.initial(false),
|
||||||
@@ -127,8 +133,6 @@ extends Pipeable.Class implements Query<K, A, E, R> {
|
|||||||
> {
|
> {
|
||||||
return Effect.gen({ self: this }, function*() {
|
return Effect.gen({ self: this }, function*() {
|
||||||
yield* this.interrupt
|
yield* this.interrupt
|
||||||
yield* Lens.set(this.key, key)
|
|
||||||
|
|
||||||
const state = yield* this.startCached({
|
const state = yield* this.startCached({
|
||||||
key,
|
key,
|
||||||
result: AsyncResult.initial(false),
|
result: AsyncResult.initial(false),
|
||||||
@@ -144,14 +148,14 @@ extends Pipeable.Class implements Query<K, A, E, R> {
|
|||||||
get refresh(): Effect.Effect<FinalQueryState<K, A, E>, Cause.NoSuchElementError> {
|
get refresh(): Effect.Effect<FinalQueryState<K, A, E>, Cause.NoSuchElementError> {
|
||||||
return Effect.gen({ self: this }, function*() {
|
return Effect.gen({ self: this }, function*() {
|
||||||
yield* this.interrupt
|
yield* this.interrupt
|
||||||
const latestKey = yield* Lens.get(this.key)
|
const latestState = yield* Lens.get(this.state)
|
||||||
const latestFinalState = yield* Lens.get(this.latestFinalState)
|
const latestFinalState = yield* Lens.get(this.latestFinalState)
|
||||||
|
|
||||||
const state = yield* this.startCached(
|
const state = yield* this.startCached(
|
||||||
Option.isSome(latestFinalState) && this.keyEquivalence(latestKey, latestFinalState.value.key)
|
Option.isSome(latestFinalState) && this.keyEquivalence(latestState.key, latestFinalState.value.key)
|
||||||
? latestFinalState.value
|
? latestFinalState.value
|
||||||
: {
|
: {
|
||||||
key: latestKey,
|
key: latestState.key,
|
||||||
result: AsyncResult.initial(false),
|
result: AsyncResult.initial(false),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -168,14 +172,14 @@ extends Pipeable.Class implements Query<K, A, E, R> {
|
|||||||
> {
|
> {
|
||||||
return Effect.gen({ self: this }, function*() {
|
return Effect.gen({ self: this }, function*() {
|
||||||
yield* this.interrupt
|
yield* this.interrupt
|
||||||
const latestKey = yield* Lens.get(this.key)
|
const latestState = yield* Lens.get(this.state)
|
||||||
const latestFinalState = yield* Lens.get(this.latestFinalState)
|
const latestFinalState = yield* Lens.get(this.latestFinalState)
|
||||||
|
|
||||||
const state = yield* this.startCached(
|
const state = yield* this.startCached(
|
||||||
Option.isSome(latestFinalState) && this.keyEquivalence(latestKey, latestFinalState.value.key)
|
Option.isSome(latestFinalState) && this.keyEquivalence(latestState.key, latestFinalState.value.key)
|
||||||
? latestFinalState.value
|
? latestFinalState.value
|
||||||
: {
|
: {
|
||||||
key: latestKey,
|
key: latestState.key,
|
||||||
result: AsyncResult.initial(false),
|
result: AsyncResult.initial(false),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -363,7 +367,7 @@ extends Pipeable.Class implements Query<K, A, E, R> {
|
|||||||
|
|
||||||
export declare namespace make {
|
export declare namespace make {
|
||||||
export interface Options<K, A, E = never, R = never> {
|
export interface Options<K, A, E = never, R = never> {
|
||||||
readonly key: Lens.Lens<K>,
|
readonly key: Subscribable.Subscribable<K>,
|
||||||
readonly keyEquivalence?: Equivalence.Equivalence<K>,
|
readonly keyEquivalence?: Equivalence.Equivalence<K>,
|
||||||
readonly f: (key: K) => Effect.Effect<A, E, R>
|
readonly f: (key: K) => Effect.Effect<A, E, R>
|
||||||
|
|
||||||
@@ -392,7 +396,7 @@ export const make = Effect.fnUntraced(function* <K, A, E = never, R = never>(
|
|||||||
|
|
||||||
Lens.fromSubscriptionRef(yield* SubscriptionRef.make(Option.none<Fiber.Fiber<A, E>>())),
|
Lens.fromSubscriptionRef(yield* SubscriptionRef.make(Option.none<Fiber.Fiber<A, E>>())),
|
||||||
Lens.fromSubscriptionRef(yield* SubscriptionRef.make<QueryState<K, A, E>>({
|
Lens.fromSubscriptionRef(yield* SubscriptionRef.make<QueryState<K, A, E>>({
|
||||||
key: yield* Lens.get(options.key),
|
key: yield* options.key.get,
|
||||||
result: AsyncResult.initial(false),
|
result: AsyncResult.initial(false),
|
||||||
})),
|
})),
|
||||||
Lens.fromSubscriptionRef(yield* SubscriptionRef.make(Option.none<FinalQueryState<K, A, E>>())),
|
Lens.fromSubscriptionRef(yield* SubscriptionRef.make(Option.none<FinalQueryState<K, A, E>>())),
|
||||||
|
|||||||
Reference in New Issue
Block a user