React practices
and do not represent opinions of my employer
=
Independently
Connected
Components
props.completed
props.todo.completed
Easy vs. Performant
Performant vs. Extensible
Extensible vs. ?
(independent of parent context)
~1700 ms 😱
ICC
react-redux < v5.0.0
~600 ms 💪
No Batcher + ICC
react-redux < v5.0.0
No Batcher + ICC
react-redux v5.0.0beta3
~500 ms 👌
Single Subscribe
react-redux v5.0.0beta3
~450 ms 👍
Single Subscribe
react-redux v5.0.0beta3
~500 ms 🤔
ICC + virtualized list
react-redux v5.0.0beta3
~200 ms 👍
State Passing is ~10% faster in our hot rendering path 🔥but ...
Single file with ~50 selectors and 25 handlers 🙀
1. Connect is partially applied
2. Index exports (component + connect)
3. Specialization goes to subdirectories
import React from 'react'
import AddTask from '../AddTask'
import connect from '../connect'
import '../addTask.styl'
export default connect(AddTask)
import { connect } from 'react-redux'
// import all other stuff
const mapStateToProps = createSelector(
// selectors go here
)
const mapActionsToProps = dispatch => ({
// map actions to event handlers here
})
export default connect(mapStateToProps, mapActionsToProps)
import AddTask from 'components/AddTask'
import Tasks from 'components/Tasks'
// import other stuff ...
// Component stuff ...
render() {
// boilerplate
return (
// some stuff here
<Tasks listId={ listEntityId }/>
<AddTask/>
// some more stuff there
)
}
Directory structure
===
state structure
1. No derived data in domains
2. Single Source of Writes
3. Represents Domain Entities
4. Indexed (byId, byOrder)
Think "a table in relational DB"
1. Derived Data is in selectors
2. Action is handled by only one reducer
3. Actions have domain-specific names
4. Dependent actions
Read (domain - domain) dependencies
Write (domain->domain) relationships
📜 SAM.js