Skip to content
Browse files

Use mutable reference to immutable map

  • Loading branch information...
1 parent 3d1d7c3 commit 21430ca4b948110b3ea55827f94bea0c9a2edb89 @pbrant pbrant committed with fmpwizard
View
8 web/webkit/src/main/scala/net/liftweb/http/CssBoundLiftScreen.scala
@@ -22,8 +22,7 @@ import net.liftweb.common._
import util._
import xml._
-
-import collection.mutable.{Map => MutableMap}
+import java.util.concurrent.atomic.AtomicReference
trait CssBoundLiftScreen extends LiftScreen with CssBoundScreen {
protected object SavedDefaultXml extends ScreenVar[NodeSeq](defaultXml) {
@@ -46,7 +45,8 @@ trait CssBoundLiftScreen extends LiftScreen with CssBoundScreen {
override lazy val __nameSalt = Helpers.nextFuncName
}
- protected object LocalActions extends ScreenVar[MutableMap[String, () => JsCmd]](MutableMap[String, () => JsCmd]()) {
+ protected object LocalActions extends ScreenVar[AtomicReference[Map[String, () => JsCmd]]](
+ new AtomicReference[Map[String, () => JsCmd]](Map.empty)) {
override lazy val __nameSalt = Helpers.nextFuncName
}
@@ -58,7 +58,7 @@ trait CssBoundLiftScreen extends LiftScreen with CssBoundScreen {
protected def savedDefaultXml = SavedDefaultXml.get
override protected def doFinish(): JsCmd= {
- val fMap: MutableMap[String, () => JsCmd] = LocalActions.get
+ val fMap: Map[String, () => JsCmd] = LocalActions.get.get
if (! LocalAction.get.isEmpty)
fMap.get(LocalAction.get) map (_()) getOrElse (
throw new IllegalArgumentException("No local action available with that binding"))
View
9 web/webkit/src/main/scala/net/liftweb/http/CssBoundScreen.scala
@@ -28,7 +28,7 @@ import xml._
import FieldBinding._
-import collection.mutable.{Map => MutableMap}
+import java.util.concurrent.atomic.AtomicReference
trait CssBoundScreen extends ScreenWizardRendered with Loggable {
self: AbstractScreen =>
@@ -41,7 +41,7 @@ trait CssBoundScreen extends ScreenWizardRendered with Loggable {
protected val LocalActionRef: AnyVar[String, _]
protected val LocalAction: AnyVar[String, _]
- protected val LocalActions: AnyVar[MutableMap[String, () => JsCmd], _]
+ protected val LocalActions: AnyVar[AtomicReference[Map[String, () => JsCmd]], _]
val NextId: AnyVar[String, _]
@@ -99,7 +99,10 @@ trait CssBoundScreen extends ScreenWizardRendered with Loggable {
protected def mapLocalAction[T](func: () => JsCmd)(f: String => T): T = {
val name = randomString(20)
- LocalActions.get += (name -> func)
+ val ref = LocalActions.get
+ ref.synchronized {
+ ref.set(ref.get + (name -> func))
+ }
f(name)
}

0 comments on commit 21430ca

Please sign in to comment.
Something went wrong with that request. Please try again.