Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More specific types for ref async extensions #631

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions modules/core/js/src/main/scala/crystal/react/syntax/effect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,17 @@ trait effect {
inline def modStateAsync(f: S => S): Reusable[DefaultA[Unit]] =
self.modState(f).map(_.to[DefaultA])

extension [A](self: Hooks.UseRef[A])
inline def setIn[F[_]: Sync](a: A): F[Unit] = self.set(a).to[F]
extension [A](self: NonEmptyRef.Get[A])
inline def getIn[F[_]: Sync]: F[A] = self.get.to[F]
inline def getAsync: DefaultA[A] = getIn[DefaultA]

extension [A](self: NonEmptyRef.Set[A])
inline def setIn[F[_]: Sync](a: A): F[Unit] = self.set(a).to[F]
inline def setAsync: A => DefaultA[Unit] = setIn[DefaultA](_)

extension [A](self: NonEmptyRef.Simple[A])
inline def modIn[F[_]: Sync](f: A => A): F[Unit] = self.mod(f).to[F]
inline def getIn[F[_]: Sync]: F[A] = self.get.to[F]
inline def setAsync: A => DefaultA[Unit] = setIn[DefaultA](_)
inline def modAsync: (A => A) => DefaultA[Unit] = modIn[DefaultA](_)
inline def getAsync: DefaultA[A] = getIn[DefaultA]

extension [S](self: UseSerialState[S])
inline def setStateAsync: Reusable[S => DefaultA[Unit]] =
Expand Down
Loading