Last active
August 29, 2015 14:17
-
-
Save mrjjwright/115abe0bf6e1ec9239a2 to your computer and use it in GitHub Desktop.
Few Component nesting
This file contains 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 Cocoa | |
import Few | |
private func render1(component: Few.Component<()>, state: ()) -> Element { | |
return View(backgroundColor: NSColor.redColor()) | |
.direction(.Column) | |
.flex(1) | |
} | |
let Component1: () -> Few.Component<()> = { Component(initialState: (), render: render1) } | |
private func render2(component: Few.Component<()>, state: ()) -> Element { | |
return View(backgroundColor: NSColor.blueColor()) | |
.direction(.Column) | |
.flex(1) | |
} | |
let Component2: () -> Few.Component<()> = { Component(initialState: (), render: render2) } | |
func renderApp(component: Few.Component<()>, state: ()) -> Element { | |
return View(backgroundColor: NSColor.greenColor()) | |
.direction(.Row) | |
.children([ | |
Component1(), | |
Component2() | |
]) | |
} | |
class AppDelegate: NSObject, NSApplicationDelegate { | |
@IBOutlet weak var window: NSWindow! | |
private let appComponent = Component(initialState: (), render: renderApp) | |
func applicationDidFinishLaunching(notification: NSNotification) { | |
let contentView = window.contentView as NSView | |
appComponent.addToView(contentView) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment