Last active
September 16, 2022 10:24
-
-
Save vikingosegundo/7bf036c4586fddfed33dccc2eb32bd27 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
public | |
final class ViewState: ObservableObject { | |
@Published public var lights : [Light ] = [] | |
@Published public var rooms : [Room ] = [] | |
@Published public var favorites : [Favorite] = [] | |
public init(store:Store<AppState,AppState.Change>) { | |
store.updated { self.process(state(in:store)) } | |
process(store.state()) | |
} | |
public func handle(msg: Message) { } | |
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