Created
November 24, 2021 19:54
-
-
Save vikingosegundo/4cedad876baa7120521d0e795c6f6eba 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
import SwiftUI | |
import BrighterModel | |
final class ViewState: ObservableObject { | |
@Published var lights : [ Light ] = [] | |
@Published var rooms : [ Room ] = [] | |
@Published var favorites: [ Favorite ] = [] | |
init(store: Store) { | |
store.updated { self.process(state(in: store)) } | |
process(state(in: store)) | |
} | |
private func process(_ appState: AppState) { | |
DispatchQueue.main.async { | |
self.lights = appState.lights.sorted(on:\.name, by:<) | |
self.rooms = appState.rooms.sorted(on:\.title, by:<) | |
self.favorites = appState.favorites | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment