Rename save function to patch to be less confusing (it doesn't actually save anything).
This commit is contained in:
parent
8f8dafed5b
commit
6eee1b709e
4 changed files with 11 additions and 11 deletions
|
@ -19,7 +19,7 @@
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img alt="Version 3.2.2" src="https://img.shields.io/badge/version-3.2.2-blue" />
|
<img alt="Version 3.3.0" src="https://img.shields.io/badge/version-3.3.0-blue" />
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
Sharkitek is a Javascript / TypeScript library designed to ease development of client-side models.
|
Sharkitek is a Javascript / TypeScript library designed to ease development of client-side models.
|
||||||
|
|
||||||
With Sharkitek, you define the architecture of your models by specifying their properties and their types.
|
With Sharkitek, you define the architecture of your models by specifying their properties and their types.
|
||||||
Then, you can use the defined methods like `serialize`, `deserialize`, `save` or `serializeDiff`.
|
Then, you can use the defined methods like `serialize`, `deserialize`, `patch` or `serializeDiff`.
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
class Example extends s.model({
|
class Example extends s.model({
|
||||||
|
@ -227,7 +227,7 @@ const result = model.serializeDiff();
|
||||||
// result = {}
|
// result = {}
|
||||||
```
|
```
|
||||||
|
|
||||||
#### `save()`
|
#### `patch()`
|
||||||
|
|
||||||
Get difference between original values and current ones, then reset it.
|
Get difference between original values and current ones, then reset it.
|
||||||
Similar to call `serializeDiff()` then `resetDiff()`.
|
Similar to call `serializeDiff()` then `resetDiff()`.
|
||||||
|
@ -246,7 +246,7 @@ const model = (new TestModel()).deserialize({
|
||||||
|
|
||||||
model.title = "A new title for a new world";
|
model.title = "A new title for a new world";
|
||||||
|
|
||||||
const result = model.save();
|
const result = model.patch();
|
||||||
// if `id` is defined as the model identifier:
|
// if `id` is defined as the model identifier:
|
||||||
// result = { id: 5, title: "A new title for a new world" }
|
// result = { id: 5, title: "A new title for a new world" }
|
||||||
// if `id` is not defined as the model identifier:
|
// if `id` is not defined as the model identifier:
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@sharkitek/core",
|
"name": "@sharkitek/core",
|
||||||
"version": "3.2.2",
|
"version": "3.3.0",
|
||||||
"description": "TypeScript library for well-designed model architectures.",
|
"description": "TypeScript library for well-designed model architectures.",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"deserialization",
|
"deserialization",
|
||||||
|
|
|
@ -105,7 +105,7 @@ export interface ModelDefinition<Shape extends ModelShape, IdentifierType, Model
|
||||||
* Get difference between original values and current ones, then reset it.
|
* Get difference between original values and current ones, then reset it.
|
||||||
* Similar to call `serializeDiff()` then `resetDiff()`.
|
* Similar to call `serializeDiff()` then `resetDiff()`.
|
||||||
*/
|
*/
|
||||||
save(): Partial<SerializedModel<Shape>>;
|
patch(): Partial<SerializedModel<Shape>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -248,7 +248,7 @@ export function model<ModelType extends Model<Shape, IdentifierType<Shape, Ident
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
save(): Partial<SerializedModel<Shape>>
|
patch(): Partial<SerializedModel<Shape>>
|
||||||
{
|
{
|
||||||
// Get the difference.
|
// Get the difference.
|
||||||
const diff = this.serializeDiff();
|
const diff = this.serializeDiff();
|
||||||
|
|
|
@ -109,7 +109,7 @@ it("create and check state then serialize", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it("deserialize then save", () => {
|
it("deserialize then patch", () => {
|
||||||
const article = (new Article()).deserialize({
|
const article = (new Article()).deserialize({
|
||||||
id: 1,
|
id: 1,
|
||||||
title: "this is a test",
|
title: "this is a test",
|
||||||
|
@ -130,13 +130,13 @@ it("deserialize then save", () => {
|
||||||
|
|
||||||
expect(article.isDirty()).toBeTruthy();
|
expect(article.isDirty()).toBeTruthy();
|
||||||
|
|
||||||
expect(article.save()).toStrictEqual({
|
expect(article.patch()).toStrictEqual({
|
||||||
id: 1,
|
id: 1,
|
||||||
text: "Modified text.",
|
text: "Modified text.",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("save with modified submodels", () => {
|
it("patch with modified submodels", () => {
|
||||||
const article = (new Article()).deserialize({
|
const article = (new Article()).deserialize({
|
||||||
id: 1,
|
id: 1,
|
||||||
title: "this is a test",
|
title: "this is a test",
|
||||||
|
@ -152,7 +152,7 @@ it("save with modified submodels", () => {
|
||||||
article.authors[0].name = "TEST";
|
article.authors[0].name = "TEST";
|
||||||
article.authors[1].createdAt.setMonth(9);
|
article.authors[1].createdAt.setMonth(9);
|
||||||
|
|
||||||
expect(article.save()).toStrictEqual({
|
expect(article.patch()).toStrictEqual({
|
||||||
id: 1,
|
id: 1,
|
||||||
authors: [
|
authors: [
|
||||||
{ name: "TEST" },
|
{ name: "TEST" },
|
||||||
|
|
Loading…
Reference in a new issue