Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

feat(entity): setData with optional markClean

  • Loading branch information
doktordirk committed Jul 8, 2016
1 parent 09a31e2 commit ee01480f86455c0fee2b080559f2e6a25cfe9bd4
Showing with 23 additions and 5 deletions.
  1. +5 −4 doc/api_entity.md
  2. +4 −1 src/entity.js
  3. +14 −0 test/entity.spec.js
@@ -279,15 +279,16 @@ Defaults to the resource name (or null when also not set).

---------

## .setData(data)
## .setData(data, markClean)

Set the values of the entity.

### Parameters

| Parameter | Type | Description |
| --------- | ------ | ------------------------------------------ |
| data | object | An object of data to assign to the entity. |
| Parameter | Type | Description |
| --------- | ------- | ------------------------------------------ |
| data | object | An object of data to assign to the entity. |
| markClean | boolean | Optionally, marks entity as clean |

### Returns

@@ -365,11 +365,14 @@ export class Entity {
* Set data on this entity.
*
* @param {{}} data
* @param {boolean} markClean
* @return {Entity}
*/
setData(data) {
setData(data, markClean) {
Object.assign(this, data);

if (markClean) this.markClean();

return this;
}

@@ -539,6 +539,20 @@ describe('Entity', function() {
expect(entity.cake).toEqual('delicious');
expect(entity.but).toEqual('So is bacon');
expect(entity.asObject()).toEqual({cake: 'delicious', but: 'So is bacon'});
expect(entity.isDirty()).toEqual(true);
});

it('Should set data on an entity and mark clean.', function() {
let entity = new Entity();

entity.setResource('unittest .setDate');

entity.setData({cake: 'delicious', but: 'So is bacon'}, true);

expect(entity.cake).toEqual('delicious');
expect(entity.but).toEqual('So is bacon');
expect(entity.asObject()).toEqual({cake: 'delicious', but: 'So is bacon'});
expect(entity.isDirty()).toEqual(false);
});
});

0 comments on commit ee01480

Please sign in to comment.