Created
September 10, 2022 15:04
-
-
Save vikingosegundo/ebd2c3be105794ca7c2d9e321e71dd29 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
func createDiskStore( | |
pathInDocs p: String , | |
fileManager fm: FileManager = .default | |
) -> Store<AppState, AppState.Change> | |
{ | |
var state = loadAppStateFromStore(pathInDocuments:p,fileManager:fm) { didSet { callbacks.forEach { $0() } } } | |
var callbacks: [() -> ()] = [] | |
return ( | |
state : { state }, | |
change : { state = state.alter($0) ; persistStore(pathInDocuments:p, state:state, fileManager:fm) }, | |
reset : { state = AppState() ; persistStore(pathInDocuments:p, state:state, fileManager:fm) }, | |
updated : { callbacks = callbacks + [$0] }, | |
destroy : { destroyStore(pathInDocuments:p,fileManager:fm) } | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment