One step at a time
Composability is a system design principle that deals with the inter-relationships of components. A highly composable system provides components that can be selected and assembled in various combinations to satisfy specific user requirements.
A Composable System is one where:
Or in React terms:
There's nothing boaty or airplaney or helicoptery about any of the bricks, but they can be combined to make any of those things or more...
Why are we even here?
Scope creep, deadlines, hacky bug-fixes, and even well-intentioned feature development all lead to an inevitably brittle result.
<div class="blog-post">
<h1 class="blog-title">Lorem ipsum dolor</h1>
<h2 class="byline">by Josh Lee</h2>
<p class="lede">Once upon a midnight dreary...</p>
<p>No, I'm not a poet</p>
</div>
<blogPost post={post} />
const blogPost = (props) => {
return
<div className="blog-post">
<h1 className="blog-title">{props.post.title}</h1>
<h2 className="blog-byline">by {props.post.author}</h2>
...
</div>;
}
class blogPost extends React.component {
function render() {
return
<div className="blog-post">
<h1 className="blog-title">{this.props.post.title}</h1>
<h2 className="blog-byline">by {this.props.post.author}</h2>
...
</div>;
}
}
rendered_componented = f(data)
More at the official tutorial
class Square extends React.Component {
render() {
return (
<button className="square">
{this.props.value}
</button>
);
}
}
class Board extends React.Component {
renderSquare(i) {
return (
<Square
value={this.props.squares[i]}
onClick={() => this.props.onClick(i)}
/>
);
}
render() {
const status = 'Next player: X';
return (
<div>
<div className="status">{status}</div>
<div className="board-row">
{this.renderSquare(0)}
{this.renderSquare(1)}
{this.renderSquare(2)}
</div>
...
</div>
);
}
}
It asks you to:
{
"counters":
{
"byId":
{
"6":{"label":"hp","creatureId":"7","id":"6","count":0},
"7":{"label":"hp","creatureId":"2","id":"7","count":200},
"5":{"label":"hp","creatureId":"3","id":"5","count":10}
},
"allIds":["6","7","5"]},
"creatures":
{
"byId":
{"7":{"name":"Josh","id":"7","counterIds":["6"]},
"2":{"name":"Kim","id":"2","counterIds":["7"]},
"3":{"name":"Sam","id":"3","counterIds":["5"]}},
"allIds":["3","2","7"]
}
}
(The duplication is because JSON doesn't enforce order on object keys)