1
1
# Few.swift
2
2
3
- [ React] ( http://facebook.github.io/react/ ) -inspired library in Swift for writing
4
- UIs which are functions of their state.<sup ><a href =" #lol " >1</a ></sup >
3
+ [ React] ( http://facebook.github.io/react/ ) -inspired library for writing
4
+ AppKit/UIKit UIs which are functions of their state.<sup ><a href =" #lol " >1</a ></sup >
5
5
6
6
[ SwiftBox] ( https://github.com/joshaber/SwiftBox ) is used for layout.
7
7
@@ -10,11 +10,11 @@ UIs which are functions of their state.<sup><a href="#lol">1</a></sup>
10
10
[ UIs are big, messy, mutable, stateful bags of sadness.] ( http://joshaber.github.io/2015/01/30/why-react-native-matters/ )
11
11
12
12
Few.swift lets us express UIs as stateless, composable, immutable-ish values of
13
- their state. When their state changes, Few.swift calls a designated render
14
- function and intelligently applies any changes.
13
+ their state. When their state changes, Few.swift calls a function to render the
14
+ UI for that state, and then intelligently applies any changes.
15
15
16
- The state is the necessary complexity of the view . The view is a mapping from
17
- state to its representation.
16
+ To put it another way, the state is the necessary complexity of the app . The
17
+ view is a mapping from state to its representation.
18
18
19
19
## Example
20
20
@@ -46,7 +46,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
46
46
private let appComponent = Component (initialState : 0 , render : renderApp)
47
47
48
48
func applicationDidFinishLaunching (notification : NSNotification) {
49
- let contentView = window.contentView as! NSView
49
+ let contentView = window.contentView as NSView
50
50
appComponent.addToView (contentView)
51
51
}
52
52
}
@@ -80,7 +80,6 @@ private func renderLabeledInput(label: String, value: String, autofocus: Bool, f
80
80
Input (
81
81
text : value,
82
82
placeholder : label,
83
- enabled : true ,
84
83
action : fn)
85
84
// Autofocus means that the Input will become the first responder when
86
85
// it is first added to the window.
@@ -117,6 +116,9 @@ private func render(component: Few.Component<ConverterState>, state: ConverterSt
117
116
}
118
117
```
119
118
119
+ This is super cool because the only thing that's mutating is the state. Few.swift
120
+ is in charge of making an in-place changes to the UI when the state changes.
121
+
120
122
See [ FewDemo] ( FewDemo ) for some more involved examples.
121
123
122
124
## How does this compare to React-Native/Components?
0 commit comments