import { Either, Match, Option, pipe } from "effect";
import { constVoid } from "effect/Function";
import { watch, type WatchOptions } from "vue";
import type { WatchResultArgs } from "./watch-result.types";
export function watchResult<L, R>(
data: Ref<Either.Either<R, L> | undefined>,
args: WatchResultArgs<L, R>,
opts?: WatchOptions,
) {
return watch(
data,
(value) => {
return pipe(
value,
Option.fromNullable,
Option.map(
Either.match({
onLeft: (error) => Match.valueTags(error)(args.onError), // Issue here
onRight: (value) => args.onSuccess(value),
}),
),
Option.getOrElse(constVoid),
);
},
opts,
);
}
import { Either, Match, Option, pipe } from "effect";
import { constVoid } from "effect/Function";
import { watch, type WatchOptions } from "vue";
import type { WatchResultArgs } from "./watch-result.types";
export function watchResult<L, R>(
data: Ref<Either.Either<R, L> | undefined>,
args: WatchResultArgs<L, R>,
opts?: WatchOptions,
) {
return watch(
data,
(value) => {
return pipe(
value,
Option.fromNullable,
Option.map(
Either.match({
onLeft: (error) => Match.valueTags(error)(args.onError), // Issue here
onRight: (value) => args.onSuccess(value),
}),
),
Option.getOrElse(constVoid),
);
},
opts,
);
}