Created
March 25, 2020 18:57
-
-
Save ZakTaccardi/4675de7923a57d95342b018b6ae73551 to your computer and use it in GitHub Desktop.
scoping of data
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
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