Created
October 3, 2011 09:08
-
-
Save eiennohito/1258749 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package code.comet | |
import net.liftweb._ | |
import http._ | |
import util._ | |
/** | |
* The screen real estate on the browser will be represented | |
* by this component. When the component changes on the server | |
* the changes are automatically reflected in the browser. | |
*/ | |
class Chat extends CometActor with CometListener { | |
private var msgs = List.empty[String] | |
/** | |
* When the component is instantiated, register as | |
* a listener with the ChatServer | |
*/ | |
def registerWith = ChatServer | |
/** | |
* The CometActor is an Actor, so it processes messages. | |
* In this case, we're listening for Vector[String], | |
* and when we get one, update our private state | |
* and reRender() the component. reRender() will | |
* cause changes to be sent to the browser. | |
*/ | |
override def lowPriority = { | |
case v: List[String] => msgs = v; reRender() | |
} | |
/** | |
* Put the messages in the li elements and clear | |
* any elements that have the clearable class. | |
*/ | |
def render = { | |
val smt = msgs map {m => m + "asdf"} | |
"li *" #> smt & ClearClearable | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment