1.0.0 • Published 7 years ago
opensupports-redux-classes v1.0.0
opensupports-redux-classes
This is an utility for having reducers as classes in a Redux architecture.
Usage
const { Reducer } = require('opensupports-redux-classes');
class MyReducer extends Reducer {
getInitialState() {
return {
opened: false
};
}
getTypeHandlers() {
return {
'OPEN': this.handleOpen.bind(this),
'CLOSE': this.handleClose.bind(this)
};
}
handleOpen(state) {
return {
...state,
opened: true
};
}
handleClose(state) {
return {
...state,
opened: false
};
}
}
module.exports = MyReducer.getInstance();This will export a reducer that:
- Its initial state is
opened: false - When
'OPEN'action happens, it replaces the state it withopened: true - When
'CLOSE'action happens, it replaces the state it withopened: false
1.0.0
7 years ago