Loading
Juraj Kirchheim
This is a live streamed presentation. You will automatically follow the presenter and see the slide they're currently on.
nobody knows what they want:
stakeholders use vague language that doesn't nail down the problem
programmers use strict language that could, but:
programmers prefer working on everything else
the software, from the user perspective
a nightmare, from the developer perspective
Countless attempts to fix it:
HMVC, MVP, MMVC, MVVM
Do they though?
class Counter extends React.Component {
state = { count: 1 };
render() {
return <button onClick={handleClick}>
{this.state.count}
</button>
}
handleClick = () => this.setState({
count: this.state.count + (this.props.step | 1)
})
}
<Counter step={10} />
<Counter />
All internal state is in the state object and setState updates and schedules redraw.
Same: State change invalidates component, which then updates.
Different: A React view uses the same code for creating and updating a component (via vdom diffing).
Single temparature input:
What if we need multiple ones?
class TemperatureInput extends React.Component {
state = { value: 0 }
render() {
<label>
<input
type="number"
value={this.state.value}
onChange={e => this.setState({ value: e.target.valueAsNumber })}
/>
°C
</label>
}
}
It's all in the props now.
class TemperatureInput extends React.Component {
render() {
<label>
<input
type="number"
value={this.props.value}
onChange={e => this.props.onChange(e.target.valueAsNumber)}
/>
{this.props.unit}
</label>
}
}
class Converter extends React.Component {
state = { kelvin: 293.15 };
render() {
return <div>
<TemperatureInput
value={kToF(this.state.kelvin)} unit="°F"
onChange={(value) => this.setState({ kelvin: fToK(value) })}
/>
<TemperatureInput
value={kToC(this.state.kelvin)} unit="°C"
onChange={(value) => this.setState({ kelvin: cToK(value) })}
/>
<TemperatureInput
value={this.state.kelvin} unit="K"
onChange={(value) => this.setState({ kelvin: value })}
/>
</div>
}
}
The whole subtree invalidates
The root has both business and presentation logic
Purely functional: Redux
Object oriented: MobX
typedef Reducer<State, Action> = State->Action->State;
Congratulation, you've reinvented state machines \o/
Usage: Create pure view functions and perform occult ceremonies to connect them to the store.
ProTip: it's a useful pattern in moderation.
Model your data as objects.
Decorate models with @observable and @computed
and views with @observer.
While rendering, views subscribe to changes of the data they rendered and update accordingly.
89 files changed, 376 insertions(+), 427 deletions(-)
OpenFl: exists merely as tutorial for now, but once Haxe FeathersUI is public, it's going to be a thing!