Skip to content

Instantly share code, notes, and snippets.

@ZakTaccardi
Created March 25, 2020 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZakTaccardi/4675de7923a57d95342b018b6ae73551 to your computer and use it in GitHub Desktop.
Save ZakTaccardi/4675de7923a57d95342b018b6ae73551 to your computer and use it in GitHub Desktop.
scoping of data
typealias Session = String
typealias SessionId = String
// Global Graph
interface GlobalGraph {
val sessionCache: SessionCache
}
// 1 - Global state
// globalGraph.sessionCache.getCurrentSession()
interface SessionCache {
fun getCurrentSession(): Session
}
// 2 - Global state with method injection
// globalGraph.sessionCache.getSession(sessionId)
interface SessionCache {
fun getSession(sessionId: SessionId): Session
}
// 3 - Scoped state
// globalGraph.sessionCache.getSession(sessionId)
interface GlobalGraph {
val sessionGraph: SessionGraph
}
interface SessionGraph {
val sessionId: SessionId
val sessionCache: SessionCache
}
class SessionCache(private val sessionId: SessionId) {
fun getSession(): Session = TODO()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment