Created
December 6, 2021 18:24
-
-
Save vikingosegundo/d386db2209b9cfadc7de73c869450635 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 Foundation | |
import BrighterModel | |
typealias Input = (Message) -> () | |
typealias Output = (Message) -> () | |
enum StackKind { case hue, mock } | |
func createAppDomain( | |
store : Store, | |
receivers : [Input], | |
stackKind : StackKind = .hue, | |
rootHandler: @escaping Output) -> Input | |
{ | |
store.updated { | |
#if targetEnvironment(simulator) | |
print("\(state(in: store))") | |
#endif | |
} | |
let stack = stack(of: stackKind) | |
let features: [Input] = [ | |
createLightingFeature (store:store, lightsStack:stack, output:rootHandler), | |
createDashboardFeature(store:store, output:rootHandler), | |
createLoggingFeature() | |
] | |
return { msg in | |
(receivers + features).forEach { $0(msg) } | |
} | |
} | |
fileprivate func stack(of kind:StackKind) -> LightsStack { | |
switch kind { | |
case .hue : return LightsStack(client: HueClient(ip:"192.168.178.37", user:"0cpSVXBH47AspTz8yz6xzPRH4e4DHIktuE18IUhd")) | |
case .mock: return LightsStack(client: MockClient(with: thelights, rooms: [] )) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment