Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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