Skip to content

Instantly share code, notes, and snippets.

@vikingosegundo
Created November 24, 2021 19:54
Show Gist options
  • Save vikingosegundo/4cedad876baa7120521d0e795c6f6eba to your computer and use it in GitHub Desktop.
Save vikingosegundo/4cedad876baa7120521d0e795c6f6eba to your computer and use it in GitHub Desktop.
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