Skip to content

Instantly share code, notes, and snippets.

@vikingosegundo
Created December 6, 2021 18:24
Show Gist options
  • Save vikingosegundo/d386db2209b9cfadc7de73c869450635 to your computer and use it in GitHub Desktop.
Save vikingosegundo/d386db2209b9cfadc7de73c869450635 to your computer and use it in GitHub Desktop.
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