Skip to content

Instantly share code, notes, and snippets.

@vikingosegundo
Last active September 16, 2022 10:24
Show Gist options
  • Save vikingosegundo/7bf036c4586fddfed33dccc2eb32bd27 to your computer and use it in GitHub Desktop.
Save vikingosegundo/7bf036c4586fddfed33dccc2eb32bd27 to your computer and use it in GitHub Desktop.
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