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 turn (_ light:Light, _ onOrOff:Turn ) { rootHandler( .lighting(.turn(light,onOrOff)) ) } | |
func apply ( values:Light.Values, on light:Light) { rootHandler( .lighting(.apply(.values(values),on:light)) ) } | |
func increase( value :Light.Value, by inc :Light.Value.Increment, on light:Light) { rootHandler( .lighting(.increase(value,by:inc,on:light)) ) } | |
func decrease( value :Light.Value, by dec :Light.Value.Increment, on light:Light) { rootHandler( .lighting(.decrease(value,by:dec,on:light)) ) } |
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)) } |
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
// store changes | |
store.change(.by(.adding (.favorite(fav)))) | |
store.change(.by(.removing(.favorite(fav)))) | |
store.change(.by(.replacing(.light(with:light)))) | |
// listen for updates | |
store.updated { self.process(state(in: store)) } |
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 Foundation.NSFileManager | |
func createDiskStore( | |
pathInDocs p: String = "state.json", | |
fileManager fm: FileManager = .default | |
) -> Store | |
{ | |
var state = loadAppStateFromStore(pathInDocuments: p, fileManager: fm) { didSet { callbacks.forEach { $0() } } } | |
var callbacks: [() -> ()] = [] | |
return ( |
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
typealias Access = ( ) -> AppState | |
typealias Change = ( AppState.Change... ) -> () | |
typealias Reset = ( ) -> () | |
typealias Callback = ( @escaping () -> () ) -> () | |
typealias Destroy = ( ) -> () | |
typealias Store = ( state: Access, change: Change, reset: Reset, updated: Callback, destroy: Destroy ) |
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 change(_ state:AppState, _ change:[AppState.Change] ) -> AppState { state.alter(change) } | |
struct AppState: Codable { | |
enum Change: Equatable { | |
case by(_By); enum _By: Equatable { | |
case adding(_Add); enum _Add: Equatable { | |
case light(Light) | |
case favorite(Favorite) } | |
case replacing(_Replace); enum _Replace: Equatable { | |
case lights(with:[Light]) |
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
//MARK: - Message | |
enum Message { | |
case lighting(_Lighting) | |
case dashboard(_Dashboard) | |
case logging(_Logging) | |
} | |
//MARK: - Common Lighting DSL Elements | |
enum Outcome { case succeeded, failed(Error?) } | |
enum Items { case lights, rooms } |
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 newLight() -> Light { | |
Light(id:"01", name:"01").alter( | |
by: | |
.setting(.brightness (to:0.5 )), | |
.setting(.hue (to:0.5 )), | |
.setting(.saturation (to:0.5 )), | |
.setting(.temperature(to:200.mk)), | |
.turning(.it(.on)) | |
) | |
} |
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 BrighterUI | |
import BrighterModel | |
@main | |
final | |
class BrighterHueApp: App { | |
init() { | |
rootHandler(.lighting(.load(.lights))) |
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
struct Light:Codable, Equatable, Identifiable { | |
enum Change { | |
case renaming(_RenameIt); enum _RenameIt { case it (to:String) } | |
case turning (_TurnIt ); enum _TurnIt { case it (Turn) } | |
case adding (_Add ); enum _Add { case mode (Light.Mode) } | |
case toggling(_Toggle ); enum _Toggle { case display(to:Interface) } | |
case setting (_Set ); enum _Set { | |
case hue (to:Double ) | |
case saturation (to:Double ) | |
case brightness (to:Double ) |