Skip to content

Latest commit

 

History

History
150 lines (111 loc) · 5.87 KB

File metadata and controls

150 lines (111 loc) · 5.87 KB

UI Component

Big ideas:

  • Purely functional UIs
  • Single atom app states
  • Immutability
  • State container

Segmentation of the UI along these functional boundaries. Black-boxing. Predictable input and output.

Create dependency graph for your UI! To help coder to visual hierarchy also.

Button

class Button extends React.Component {
  render() {
    var className = cx('btn', this.props.primary && 'btn-primary');
    return <button type="button" className={className} onClick={this.props.onClick}>{this.props.children}</button>;
  }
}

Showcase

UI Widget Names

UI Libraries

CSS

?

At any point in time, you describe how you want your UI to look like.

Human has limit. Working memory is finite.

Cyclomatic complexity can be used to look at your UI code.

Keep complexity down. Push simplicity up. Simple make easy - Closure

White-boarding a user experience - Moving from state to state from UI. As the number of interface states increase, what happen?

Your rendering target is the DOM. DOM is a way to get stuffs into your face. The DOM is a scene graph. Retained mode rendering.

Modelling the transition between states. Don't use imperative code.

if (count > 99) {
  if (!hasFire()) {
    addFire();
  }
} else {
  if (hasFire()) {
    removeFire();
  }
}
if (count == 0) {
  if (hasBadge()) {
    removeBadge();
  }
  return;
}
if (!hasBadge()) {
  addBadge();
}
var countText = count > 99 ? '99+' : count.toString();
getBadge().setText(countText);

Imperative UI coding is very hard to maintain and extend.

Declarative UI coding like React make you model the states as it is. Given the input, what the final state will look like.

Model states, not transitions!

Let React be your "immediate mode" to tell what the scene will look like over and over again.

React allow you to write your own DSL, your own components, your own HR lexicon!

<Pipeline>

</Pipeline

Think of React as a platform

Root Component

Your render tree.

Don't feed any data as props to your ROOT component (if you can help it) Have your root component manage state.

A root component is a very good place to manage overall application shell's state. It is also a good place to do data caching!

Container-displayer relationship.