Skip to content

Commit

Permalink
Implement toJSON method for the model.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivandotv committed Jul 1, 2022
1 parent 8a3bf02 commit aeaa369
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/stupid-islands-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@fuerte/core': minor
---

Implement `toJSON` method for the model.
Internally this method return `model.payload`
6 changes: 6 additions & 0 deletions packages/core/src/__tests__/model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,10 @@ describe('Model #model', () => {

expect(model.isNew).toBe(false)
})

test('model toJSON method equals model payload', () => {
const model = fixtures.model()

expect(model.toJSON()).toBe(model.payload)
})
})
4 changes: 4 additions & 0 deletions packages/core/src/model/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,4 +468,8 @@ export abstract class Model<

// @internal
onDestroy(): void {}

toJSON(): Payload<this> {
return this.payload
}
}

0 comments on commit aeaa369

Please sign in to comment.