-
-
Save ArcticLight/a38ad86862d0d16cddc2 to your computer and use it in GitHub Desktop.
This file contains 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
/////////////////////////////////////////////////////////////////////// | |
// TOP SECRET METEORCODE ENGINEERING BULLSHIT -- DO NOT STEAL // | |
// (c) Hawk Weisman, all rights reserved 'n' stuff // | |
/////////////////////////////////////////////////////////////////////// | |
type Payload: Map[String,Object] | |
abstract class Event ( | |
protected val payload: Payload, | |
protected var valid: Boolean = true | |
) extends (Payload)(prefunc: (Payload) => Boolean = { | |
payload => return payload.seen(this) | |
}) => Unit { | |
// validity stuff | |
def isValid: Boolean = valid | |
def invalidate: Unit { valid = false } | |
// this is where you write the onEvent behaviour, basically - the | |
// closure body becomes the apply() method | |
def apply(payload: Map[String, Object]): Unit | |
// onEvent applies the function to the payload (there might be a better way to do this) | |
def onEvent(): Unit = if(prefunc(payload)) this(payload) | |
// honestly we could just make it mix in abstract map and get all the nice map ops | |
def patchPayload(key: String, value: Object) = payload put (key, value) | |
} | |
class Fireball(payload: Payload) | |
extends Event(payload) { (payload) => | |
// do fireball stuff here | |
println(payload.toString) | |
} | |
object EventDemo extends App { | |
val aFireball = new Fireball(Map("some key" -> "some value")) | |
aFireball.onEvent() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think that the curried syntax may actually be