object
, también. Una herramienta útil para manejar objetos es la utilidad Object.assign()
. Object.assign()
toma un objeto de destino y objetos de origen y asigna propiedades de los objetos de origen al objeto de destino. Cualquier propiedad coincidente se sobrescribe con las propiedades en los objetos de origen. Este comportamiento se usa comúnmente para hacer copias superficiales de objetos al pasar un objeto vacío como el primer argumento seguido por los objetos que desea copiar. Aquí hay un ejemplo: const newObject = Object.assign({}, obj1, obj2);
Esto crea newObject
como un nuevo object
, que contiene las propiedades que existen actualmente en obj1
y obj2
. object
para el state
. Edite el código para devolver un nuevo objeto de state
para acciones con el tipo ONLINE
, que establece la propiedad de status
en la cadena en online
. Intenta usar Object.assign()
para completar el desafío. defaultState
declarado en la línea 1.
testString: 'assert((function() { const expectedState = { user: "CamperBot", status: "offline", friends: "732,982", community: "freeCodeCamp" }; const initialState = store.getState(); return DeepEqual(expectedState, initialState); })(), "The Redux store should exist and initialize with a state that is equivalent to the defaultState
object declared on line 1.");'
- text: wakeUp
y immutableReducer
deben ser funciones.
testString: 'assert(typeof wakeUp === "function" && typeof immutableReducer === "function", "wakeUp
and immutableReducer
both should be functions.");'
- text: El envío de una acción de tipo ONLINE
debe actualizar el status
la propiedad en estado a en online
y NO debe mutar el estado.
testString: 'assert((function() { const initialState = store.getState(); const isFrozen = DeepFreeze(initialState); store.dispatch({type: "ONLINE"}); const finalState = store.getState(); const expectedState = { user: "CamperBot", status: "online", friends: "732,982", community: "freeCodeCamp" }; return isFrozen && DeepEqual(finalState, expectedState); })(), "Dispatching an action of type ONLINE
should update the property status
in state to online
and should NOT mutate state.");'
- text: Object.assign
debe utilizar para devolver un nuevo estado.
testString: 'getUserInput => assert(getUserInput("index").includes("Object.assign"), "Object.assign
should be used to return new state.");'
```