Skip to content

Instantly share code, notes, and snippets.

@mrjjwright
Last active August 29, 2015 14:17
Show Gist options
  • Save mrjjwright/115abe0bf6e1ec9239a2 to your computer and use it in GitHub Desktop.
Save mrjjwright/115abe0bf6e1ec9239a2 to your computer and use it in GitHub Desktop.
Few Component nesting
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