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 { | |
init(id:String, name:String) { self.init(id, name, .off, 0, 0, 0, 0, .slider, [], .unset) } | |
enum Mode:Codable { case unset, hsb, ct } | |
enum Temperature { case mirek(Int) } | |
let id : String | |
let name : String | |
let isOn : Turn |
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) -> () | |
func createAppCore( | |
store : Store, | |
receivers : [Input], |
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 Input = (Message) -> () | |
typealias Output = (Message) -> () | |
func createLightingFeature(store : Store, | |
lightsStack: LightsStack, | |
output : @escaping Output) -> Input | |
{ | |
let loader = LightsLoader (lightsStack:lightsStack,store:store,responder:handle(output:output)) | |
let switcher = LightSwitcher (lightsStack:lightsStack,store:store,responder:handle(output:output)) | |
let valueSetter = LightValueSetter(lightsStack:lightsStack,store:store,responder:handle(output:output)) |
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
// Dimmer.Request | |
.increase(.brightness,by:10.pt,on:light)) | |
.decrease(.brightness,by:10.pt,on:light)) | |
.increase(.hue, by:10.pt,on:light)) | |
.decrease(.hue, by:10.pt,on:light)) | |
// Dimmer.Response | |
.increase(.brightness,by:10.pt,on:light,.succeeded ) | |
.increase(.colortemp, by:10.pt,on:light,.succeeded ) | |
.decrease(.hue, by:10.pt,on:light,.succeeded ) |
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 request(_ dimmer:Dimmer, to r:Dimmer.Request) { dimmer.request(r) } | |
struct Dimmer: UseCase { | |
enum Request { case increase(Light.Value, by:Light.Value.Increment, on:Light ) | |
case decrease(Light.Value, by:Light.Value.Increment, on:Light ) } | |
enum Response { case increase(Light.Value, by:Light.Value.Increment, on:Light, Outcome) | |
case decrease(Light.Value, by:Light.Value.Increment, on:Light, Outcome) } | |
init(lightsStack: LightsStack, store: Store, responder: @escaping (Response) -> ()) { | |
self.lightsStack = lightsStack | |
self.store = 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
// Requests | |
.lighting(.load (.lights), ) | |
.lighting(.turn (light,.on ), ) | |
.lighting(.turn (light,.off ), ) | |
.lighting(.apply(.values(.ct ( 200, 0.5)),on:light)) | |
.lighting(.apply(.values(.hsb(0.5,0.5,0.5)),on:light)) | |
.lighting(.apply(.values(.bri( 0.5)),on:light)) | |
.lighting(.increase(.brightness,by:10.pt, on:light)) | |
.lighting(.change(.name("1a"), on:light)) | |
.lighting(.change(.display(.scrubbing), 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 | |
struct ContentView: View { | |
init(viewState: ViewState, rootHandler: @escaping (Message) -> ()) { | |
self.viewState = viewState | |
self.rootHandler = rootHandler | |
self.tabColor = tabColors[0] | |
} | |
var body: some View { | |
TabView { |
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 | |
@main | |
struct SnakeApp:App { | |
var body:some Scene { | |
WindowGroup { | |
ZStack { | |
Color.black | |
.edgesIgnoringSafeArea(.all) | |
ContentView(state:ViewState( |
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 SnakeBoard:View { | |
func bodyAndTarget() -> [SnakeGame.Coordinate] { | |
(game.target() != nil | |
? [ game.target()! ] | |
: []) | |
+ game.snake().body | |
} | |
@StateObject var state:ViewState | |
let pixelFactor:Double | |
var game: SnakeGame.Game { state.game } |