<commit_before>//
//  AppDelegate.swift
//  Few
//
//  Created by <NAME> on 7/22/14.
//  Copyright (c) 2014 <NAME>. All rights reserved.
//

import Cocoa
import Few

func renderForm(buttonLabel: String, component: Few.Component<Int>, state: Int) -> Element {
	let input = Input(initialText: "", placeholder: "Text") { str in
		component.updateState(const(str.utf16Count))
		return ()
	}
	input.frame.size = CGSize(width: 100, height: 23)

	let label = Label(text: "\(state)")
	label.frame.size = CGSize(width: 100, height: 23)

	let button = Button(title: buttonLabel) {
		let rawInput = input.getContentView() as NSTextField!
		rawInput.stringValue = ""
		component.updateState(const(0))
	}
	button.frame.size = CGSize(width: 75, height: 23)

	let container = Container(children: [input, label, button], layout: horizontalStack(10))
	container.frame.size = CGSizeMake(305, 23)
	return container
}

func renderApp(component: Few.Component<Int>, state: Int) -> Element {
	return Container(children: [renderForm("Click me!", component, state), renderForm("Beat it", component, state)], layout: verticalStack(10) >-- offset(CGPoint(x: 20, y: -100)))
}

// This is to work around Swift's inability to have non-generic subclasses of a
// generic superclass.
typealias AppComponent = AppComponent_<Any>
class AppComponent_<Bullshit>: Few.Component<Int> {
	init() {
		super.init(render: renderApp, initialState: 0)
	}
}

class AppDelegate: NSObject, NSApplicationDelegate {
	@IBOutlet weak var window: NSWindow!

	private let appComponent = AppComponent()
	
	func applicationDidFinishLaunching(notification: NSNotification?) {
		let contentView = window.contentView as NSView
		appComponent.addToView(contentView)
	}
}
<commit_msg>More example.<commit_after>//
//  AppDelegate.swift
//  Few
//
//  Created by <NAME> on 7/22/14.
//  Copyright (c) 2014 <NAME>. All rights reserved.
//

import Cocoa
import Few

func renderForm(buttonLabel: String, component: Few.Component<Int>, state: Int) -> Element {
	let input = Input(initialText: "", placeholder: "Text") { str in
		component.updateState(const(str.utf16Count))
		return ()
	}
	input.frame.size = CGSize(width: 100, height: 23)

	let label = Label(text: "\(state)")
	label.frame.size = CGSize(width: 100, height: 23)

	let button = Button(title: buttonLabel) {
		input.textField?.stringValue = ""
		component.updateState(const(0))
	}
	button.frame.size = CGSize(width: 75, height: 23)

	let container = Container(children: [input, label, button], layout: horizontalStack(10))
	container.frame.size = CGSizeMake(305, 23)
	return container
}

func renderApp(component: Few.Component<Int>, state: Int) -> Element {
	let layout = verticalStack(10) >-- offset(CGPoint(x: 20, y: -100))
	let items = [renderForm("Click me!", component, state), renderForm("Beat it", component, state)]
	return Container(children: items, layout: layout)
}

// This is to work around Swift's inability to have non-generic subclasses of a
// generic superclass.
typealias AppComponent = AppComponent_<Any>
class AppComponent_<Bullshit>: Few.Component<Int> {
	init() {
		super.init(render: renderApp, initialState: 0)
	}
}

class AppDelegate: NSObject, NSApplicationDelegate {
	@IBOutlet weak var window: NSWindow!

	private let appComponent = AppComponent()
	
	func applicationDidFinishLaunching(notification: NSNotification?) {
		let contentView = window.contentView as NSView
		appComponent.addToView(contentView)
	}
}

{'fraction_non_alphanumeric': 0.13313953488372093, 'fraction_numerical': 0.023837209302325583, 'mean_word_length': 4.842105263157895, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5905518', 'n_tokens_mistral': 1200, 'n_tokens_neox': 1073, 'n_words': 300}