From cf75b85051cd649c28b421d405badde85a4050d5 Mon Sep 17 00:00:00 2001 From: ragnar Date: Sun, 3 Mar 2024 00:12:32 +0100 Subject: [PATCH] be more giving --- .../src/main/scala/reactives/core/Core.scala | 6 +++--- .../scala/reactives/core/ScopeSearches.scala | 20 +++++++++---------- .../scala/reactives/macros/MacroLego.scala | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Modules/Reactives/shared/src/main/scala/reactives/core/Core.scala b/Modules/Reactives/shared/src/main/scala/reactives/core/Core.scala index ba9e40647..e0194e624 100644 --- a/Modules/Reactives/shared/src/main/scala/reactives/core/Core.scala +++ b/Modules/Reactives/shared/src/main/scala/reactives/core/Core.scala @@ -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] = diff --git a/Modules/Reactives/shared/src/main/scala/reactives/core/ScopeSearches.scala b/Modules/Reactives/shared/src/main/scala/reactives/core/ScopeSearches.scala index 7ee84a505..623ddb23f 100644 --- a/Modules/Reactives/shared/src/main/scala/reactives/core/ScopeSearches.scala +++ b/Modules/Reactives/shared/src/main/scala/reactives/core/ScopeSearches.scala @@ -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[_]] { @@ -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) } @@ -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) diff --git a/Modules/Reactives/shared/src/main/scala/reactives/macros/MacroLego.scala b/Modules/Reactives/shared/src/main/scala/reactives/macros/MacroLego.scala index 8b2b26b74..262e469a2 100644 --- a/Modules/Reactives/shared/src/main/scala/reactives/macros/MacroLego.scala +++ b/Modules/Reactives/shared/src/main/scala/reactives/macros/MacroLego.scala @@ -1,6 +1,6 @@ package reactives.macros -import reactives.core.{CreationScope, Transaction, TransactionScope} +import reactives.core.{CreationScope, Transaction, TransactionSearch} import scala.quoted.* @@ -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) }