2016-02-13 20:58:47 +05:30
|
|
|
import { UPDATE, SET } from './actions';
|
|
|
|
|
|
|
|
import User from './User';
|
|
|
|
|
2016-02-26 23:43:41 +05:30
|
|
|
// TODO: возможно есть смысл инитить обьект User снаружи, так как редусер не должен столько знать
|
2016-02-13 20:58:47 +05:30
|
|
|
export default function user(
|
|
|
|
state = new User(),
|
|
|
|
{type, payload = null}
|
|
|
|
) {
|
|
|
|
switch (type) {
|
|
|
|
case UPDATE:
|
|
|
|
if (!payload) {
|
|
|
|
throw new Error('payload is required for user reducer');
|
|
|
|
}
|
|
|
|
|
|
|
|
return new User({
|
|
|
|
...state,
|
|
|
|
...payload
|
|
|
|
});
|
2016-02-26 23:43:41 +05:30
|
|
|
|
2016-02-13 20:58:47 +05:30
|
|
|
case SET:
|
|
|
|
return new User(payload || {});
|
|
|
|
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|