@@ -129,6 +129,49 @@ export const makeLazy = <A, ER, EW, RR, RW>(
|
||||
): Lens<A, ER, EW, RR, RW> => new LensLazyImpl(source)
|
||||
|
||||
|
||||
export declare namespace SynchronizedRefLensImpl {
|
||||
export interface SynchronizedRefWithInternals<in out A>
|
||||
extends SynchronizedRef.SynchronizedRef<A> {
|
||||
readonly ref: Ref.Ref<A>
|
||||
readonly withLock: <A1, E1, R1>(self: Effect.Effect<A1, E1, R1>) => Effect.Effect<A1, E1, R1>
|
||||
}
|
||||
}
|
||||
|
||||
export class SynchronizedRefLensImpl<in out A>
|
||||
extends Pipeable.Class() implements LensWithInternals<A, never, never, never, never> {
|
||||
readonly [Readable.TypeId]: Readable.TypeId = Readable.TypeId
|
||||
readonly [Subscribable.TypeId]: Subscribable.TypeId = Subscribable.TypeId
|
||||
readonly [LensTypeId]: LensTypeId = LensTypeId
|
||||
readonly [LensWithInternalsTypeId]: LensWithInternalsTypeId = LensWithInternalsTypeId
|
||||
|
||||
readonly ref: SynchronizedRefLensImpl.SynchronizedRefWithInternals<A>
|
||||
|
||||
constructor(
|
||||
ref: SynchronizedRef.SynchronizedRef<A>
|
||||
) {
|
||||
super()
|
||||
this.ref = ref as SynchronizedRefLensImpl.SynchronizedRefWithInternals<A>
|
||||
}
|
||||
|
||||
get get() { return this.ref.get }
|
||||
get changes() { return Stream.unwrap(Effect.map(this.ref.get, Stream.make)) }
|
||||
update(a: A) { return Ref.set(this.ref.ref, a) }
|
||||
get withLock() { return this.ref.withLock }
|
||||
|
||||
modifyEffect = modifyEffect
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a `Lens` that proxies a `SynchronizedRef`.
|
||||
*
|
||||
* Note: since `SynchronizedRef` does not provide any kind of reactivity mechanism, the produced `Lens` will be non-reactive.
|
||||
* This means its `changes` stream will only emit the current value once when evaluated and nothing else.
|
||||
*/
|
||||
export const fromSynchronizedRef = <A>(
|
||||
ref: SynchronizedRef.SynchronizedRef<A>
|
||||
): Lens<A, never, never, never, never> => new SynchronizedRefLensImpl(ref)
|
||||
|
||||
|
||||
export declare namespace SubscriptionRefLensImpl {
|
||||
export interface SubscriptionRefWithInternals<in out A>
|
||||
extends SubscriptionRef.SubscriptionRef<A> {
|
||||
@@ -175,23 +218,6 @@ export const fromSubscriptionRef = <A>(
|
||||
): Lens<A, never, never, never, never> => new SubscriptionRefLensImpl(ref)
|
||||
|
||||
|
||||
/**
|
||||
* Creates a `Lens` that proxies a `SynchronizedRef`.
|
||||
*
|
||||
* Note: since `SynchronizedRef` does not provide any kind of reactivity mechanism, the produced `Lens` will be non-reactive.
|
||||
* This means its `changes` stream will only emit the current value once when evaluated and nothing else.
|
||||
*/
|
||||
export const fromSynchronizedRef = <A>(
|
||||
ref: SynchronizedRef.SynchronizedRef<A>
|
||||
): Lens<A, never, never, never, never> => make({
|
||||
get get() { return ref.get },
|
||||
get changes() { return Stream.unwrap(Effect.map(ref.get, Stream.make)) },
|
||||
modify: <B, E1 = never, R1 = never>(
|
||||
f: (a: A) => Effect.Effect<readonly [B, A], E1, R1>
|
||||
) => ref.modifyEffect(f),
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* Flattens an effectful `Lens`.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user