Skip to content

Instantly share code, notes, and snippets.

@scullxbones
Last active August 29, 2015 14:00
Show Gist options
  • Select an option

  • Save scullxbones/11388376 to your computer and use it in GitHub Desktop.

Select an option

Save scullxbones/11388376 to your computer and use it in GitHub Desktop.
Stake in the ground
trait ViewState { self: View =>
type State
private val state: State
def handle: Receive = {
case SnapshotOffer(metadata, offeredSnapshot) => state = offeredSnapshot
case p@Persistent(payload, sequenceNr) =>
// Handle persistent
case PersistenceFailure(payload, sequenceNr, cause) =>
// Handle persistence failure
}
}
trait PersistentViewState extends ViewState with View {
def receive = {
case p @ Persistent(payload, sequenceNr) =>
persistToDb(p)
super.handle(p)
case PersistenceFailure(payload, sequenceNr, cause) =>
receivePersistenceFailure(payload,sequenceNr,cause)
}
def persistToDb(persistent: Persistent) {
// Transform and persist to DB
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment