mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-12-04 12:39:20 +05:30
26 lines
525 B
JavaScript
26 lines
525 B
JavaScript
|
import { UPDATE, SET } from './actions';
|
||
|
|
||
|
import User from './User';
|
||
|
|
||
|
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
|
||
|
});
|
||
|
case SET:
|
||
|
return new User(payload || {});
|
||
|
|
||
|
default:
|
||
|
return state;
|
||
|
}
|
||
|
}
|