Scalable JavaScript applications that are easy to tests and maintain.
export function* deliverShipmentSaga({ payload, meta: { token } }) {
yield put(activateLoader());
const { response, error } = yield call(api.deliverShipment, payload, token);
if (response) {
yield put(deliverShipmentSuccess(response));
const toast = { content: "Shipment marked as delivered.", type: "success" };
yield fork(addToastAndRemoveIn, toast, 3000);
} else {
yield put(deliverShipmentFailure(error));
yield fork(handleError, "cannot mark shipment as delivered", error);
}
yield put(deactivateLoader());
}
import Rx from "rxjs";
function createState(reducer$, initialState$ = Rx.Observable.of({})) {
return initialState$
.merge(reducer$)
.scan((state, [scope, reducer]) =>
({ ...state, [scope]: reducer(state[scope]) }))
.publishReplay(1)
.refCount();
}
export default createState;
function connect(state$, selector = state => state) {
return function wrapWithConnect(WrappedComponent) {
return class Connect extends React.Component {
componentWillMount() {
this.subscription = state$.map(selector).subscribe(::this.setState);
}
componentWillUnmount() {
this.subscription.unsubscribe();
}
render() { ... }
};
}
}
const schema = [
["firstName", "first_name", text => text.toUpperCase()],
["cardNumber", "card.number"],
];
const mapper = mappet(schema);
const source = { first_name: "Michal", age: 21, card: { number: "555..." } };
const result = mapper(source);
// {
// firstName: "MICHAL",
// cardNumber: "5555-5555-5555-4444"
// }