Skip to content

Commit

Permalink
be more giving
Browse files Browse the repository at this point in the history
  • Loading branch information
rmgk committed Mar 2, 2024
1 parent f0545d5 commit cf75b85
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ trait Observation { def execute(): Unit }
final class CreationTicket[State[_]](val scope: CreationScope[State], val info: ReInfo)

object CreationTicket {
implicit def fromScope[State[_]](implicit scope: CreationScope[State], line: ReInfo): CreationTicket[State] =
given fromScope[State[_]](using scope: CreationScope[State], line: ReInfo): CreationTicket[State] =
new CreationTicket(scope, line)
// cases below are when one explicitly passes one of the parameters
implicit def fromTransaction[S[_]](tx: Transaction[S])(implicit line: ReInfo): CreationTicket[S] =
implicit def fromTransaction[S[_]](tx: Transaction[S])(using line: ReInfo): CreationTicket[S] =
new CreationTicket(CreationScope.StaticCreationScope(tx), line)
implicit def fromName[State[_]](str: String)(implicit
implicit def fromName[State[_]](str: String)(using
scopeSearch: CreationScope[State],
info: ReInfo
): CreationTicket[State] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ package reactives.core

import reactives.operator.Interface

case class TransactionScope[State[_]](static: Option[Transaction[State]])
object TransactionScope extends LowPrioTransactionScope {
inline given search[State[_]](using tx: Transaction[State]): TransactionScope[State] = static(tx)
inline given search[State[_]](using at: AdmissionTicket[State]): TransactionScope[State] = static(at.tx)
inline given Search[State[_]](using st: StaticTicket[State]): TransactionScope[State] = static(st.tx)
case class TransactionSearch[State[_]](static: Option[Transaction[State]])
object TransactionSearch extends LowPrioTransactionScope {
inline given search[State[_]](using tx: Transaction[State]): TransactionSearch[State] = static(tx)
inline given search[State[_]](using at: AdmissionTicket[State]): TransactionSearch[State] = static(at.tx)
inline given Search[State[_]](using st: StaticTicket[State]): TransactionSearch[State] = static(st.tx)

def static[State[_]](transaction: Transaction[State]): TransactionScope[State] = TransactionScope(Some(transaction))
def static[State[_]](transaction: Transaction[State]): TransactionSearch[State] = TransactionSearch(Some(transaction))

// non inline give variant for macro
def fromTicket[State[_]](ticket: StaticTicket[State]): TransactionScope[State] = TransactionScope(Some(ticket.tx))
def fromTicket[State[_]](ticket: StaticTicket[State]): TransactionSearch[State] = TransactionSearch(Some(ticket.tx))
}
trait LowPrioTransactionScope {
given dynamicTransactionScope[State[_]]: TransactionScope[State] = TransactionScope(None)
given dynamicTransactionScope[State[_]]: TransactionSearch[State] = TransactionSearch(None)
}

trait CreationScope[State[_]] {
Expand Down Expand Up @@ -45,7 +45,7 @@ object CreationScope {
override def embedCreation[T](f: Transaction[State] => T): T = ds.dynamicTransaction(f)
}

inline given search(using ts: TransactionScope[Interface.State]): CreationScope[Interface.State] = ts.static match
inline given search(using ts: TransactionSearch[Interface.State]): CreationScope[Interface.State] = ts.static match
case None => DynamicCreationScope(reactives.default.global.dynamicScope)
case Some(tx) => StaticCreationScope(tx)
}
Expand Down Expand Up @@ -75,7 +75,7 @@ object PlanTransactionScope {
scheduler.forceNewTransaction(inintialWrites*)(admission)
}

inline given search(using ts: TransactionScope[Interface.State]): PlanTransactionScope[Interface.State] =
inline given search(using ts: TransactionSearch[Interface.State]): PlanTransactionScope[Interface.State] =
ts.static match
case None => DynamicTransactionLookup(reactives.default.global.scheduler, reactives.default.global.dynamicScope)
case Some(tx) => StaticInTransaction(tx, reactives.default.global.scheduler)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package reactives.macros

import reactives.core.{CreationScope, Transaction, TransactionScope}
import reactives.core.{CreationScope, Transaction, TransactionSearch}

import scala.quoted.*

Expand Down Expand Up @@ -102,7 +102,7 @@ object MacroLegos {
override def transformTerm(tree: quotes.reflect.Term)(owner: quotes.reflect.Symbol): quotes.reflect.Term = {
tree match
case TypeApply(Ident("dynamicTransactionScope"), ta) =>
Apply(TypeApply(Ident(TermRef(TypeRepr.of[TransactionScope.type], "fromTicket")), ta), List(ticket))
Apply(TypeApply(Ident(TermRef(TypeRepr.of[TransactionSearch.type], "fromTicket")), ta), List(ticket))
case other =>
super.transformTerm(tree)(owner)
}
Expand Down

0 comments on commit cf75b85

Please sign in to comment.