A batteries-included, Best Practices™, approach to managing state within large, complex applications.
npm install alt --save
Action Creators
import Alt from 'alt'
function sendEmail(to, body) {
// Mocked async call
return Promise.resolve({
to,
body,
})
}
export default Alt.getActionCreators('Email', {
send(to, body) {
return Alt.asyncDispatch(
sendEmail(to, body)
)
},
})
State Branches
import { Branch } from 'alt'
import EmailActions from './EmailActions'
import alt from './alt'
class SentBox extends Branch {
constructor() {
this.namespace = 'SentBox'
this.respondToAsync(EmailActions.send, {
success: this.emailSent.bind(this),
})
this.state = {
list: [],
}
}
emailSent(email) {
const { list } = this.state
this.setState({ list: list.concat(email) })
}
}
export default alt.addBranch(new SentBox())
This library takes all the good pieces of Alt like single state tree, serialization, loading, ease-of-use, and lays it on top of a Redux-backed foundation with a few utilities included for managing asynchronous actions, and injecting your own branch state managers or reducers at runtime.
- Async & Error handling in a neat package
- Injectable reducers
- Lots of community plugins available
- Serialization/Loading
- Small API based on best practices that evolved around Alt