Skip to content

Commit 72df9f6

Browse files
committed
Change README for 3.0.0.
1 parent e43e27e commit 72df9f6

File tree

1 file changed

+52
-87
lines changed

1 file changed

+52
-87
lines changed

README.md

Lines changed: 52 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
# Sharkitek Core
22

3+
![Version 3.0.0](https://img.shields.io/badge/version-3.0.0-blue)
4+
35
## Introduction
46

57
Sharkitek is a Javascript / TypeScript library designed to ease development of client-side models.
68

79
With Sharkitek, you define the architecture of your models by specifying their properties and their types.
8-
Then, you can use the defined methods like `serialize`, `deserialize` or `serializeDiff`.
10+
Then, you can use the defined methods like `serialize`, `deserialize`, `save` or `serializeDiff`.
911

1012
```typescript
11-
class Example extends Model<Example>
13+
class Example extends s.model({
14+
id: s.property.numeric(),
15+
name: s.property.string(),
16+
})
1217
{
13-
id: number;
14-
name: string;
15-
16-
protected SDefinition(): ModelDefinition<Example>
17-
{
18-
return {
19-
id: SDefine(SNumeric),
20-
name: SDefine(SString),
21-
};
22-
}
2318
}
2419
```
2520

@@ -31,60 +26,44 @@ class Example extends Model<Example>
3126
/**
3227
* A person.
3328
*/
34-
class Person extends Model<Person>
29+
class Person extends s.model({
30+
id: s.property.numeric(),
31+
name: s.property.string(),
32+
firstName: s.property.string(),
33+
email: s.property.string(),
34+
createdAt: s.property.date(),
35+
active: s.property.boolean(),
36+
}, "id")
3537
{
36-
id: number;
37-
name: string;
38-
firstName: string;
39-
email: string;
40-
createdAt: Date;
4138
active: boolean = true;
42-
43-
protected SIdentifier(): ModelIdentifier<Person>
44-
{
45-
return "id";
46-
}
47-
48-
protected SDefinition(): ModelDefinition<Person>
49-
{
50-
return {
51-
name: SDefine(SString),
52-
firstName: SDefine(SString),
53-
email: SDefine(SString),
54-
createdAt: SDefine(SDate),
55-
active: SDefine(SBool),
56-
};
57-
}
5839
}
5940
```
6041

6142
```typescript
6243
/**
6344
* An article.
6445
*/
65-
class Article extends Model<Article>
46+
class Article extends s.model({
47+
id: s.property.numeric(),
48+
title: s.property.string(),
49+
authors: s.property.array(s.property.model(Author)),
50+
text: s.property.string(),
51+
evaluation: s.property.decimal(),
52+
tags: s.property.array(
53+
s.property.object({
54+
name: s.property.string(),
55+
})
56+
),
57+
}, "id")
6658
{
6759
id: number;
6860
title: string;
6961
authors: Author[] = [];
7062
text: string;
7163
evaluation: number;
72-
73-
protected SIdentifier(): ModelIdentifier<Article>
74-
{
75-
return "id";
76-
}
77-
78-
protected SDefinition(): ModelDefinition<Article>
79-
{
80-
return {
81-
id: SDefine(SNumeric),
82-
title: SDefine(SString),
83-
authors: SDefine(SArray(SModel(Author))),
84-
text: SDefine(SString),
85-
evaluation: SDefine(SDecimal),
86-
};
87-
}
64+
tags: {
65+
name: string;
66+
}[];
8867
}
8968
```
9069

@@ -102,53 +81,42 @@ Sharkitek defines some basic types by default, in these classes:
10281
- `DecimalType`: number in the model, formatted string in the serialized object.
10382
- `DateType`: date in the model, ISO formatted date in the serialized object.
10483
- `ArrayType`: array in the model, array in the serialized object.
84+
- `ObjectType`: object in the model, object in the serialized object.
10585
- `ModelType`: instance of a specific class in the model, object in the serialized object.
10686

107-
When you are defining a Sharkitek property, you must provide its type by instantiating one of these classes.
87+
When you are defining a property of a Sharkitek model, you must provide its type by instantiating one of these classes.
10888

10989
```typescript
110-
class Example extends Model<Example>
90+
class Example extends s.model({
91+
foo: s.property.define(new StringType()),
92+
})
11193
{
11294
foo: string;
113-
114-
protected SDefinition(): ModelDefinition<Example>
115-
{
116-
return {
117-
foo: new Definition(new StringType()),
118-
};
119-
}
12095
}
12196
```
12297

123-
To ease the use of these classes and reduce read complexity, some constant variables and functions are defined in the library,
124-
following a certain naming convention: "S{type_name}".
125-
126-
- `BoolType` => `SBool`
127-
- `StringType` => `SString`
128-
- `NumericType` => `SNumeric`
129-
- `DecimalType` => `SDecimal`
130-
- `DateType` => `SDate`
131-
- `ArrayType` => `SArray`
132-
- `ModelType` => `SModel`
98+
To ease the use of these classes and reduce read complexity,
99+
properties of each type are easily definable with a function for each type.
133100

134-
When the types require parameters, the constant is defined as a function. If there is no parameter, then a simple
135-
variable is enough.
101+
- `BoolType` => `s.property.boolean`
102+
- `StringType` => `s.property.string`
103+
- `NumericType` => `s.property.numeric`
104+
- `DecimalType` => `s.property.decimal`
105+
- `DateType` => `s.property.date`
106+
- `ArrayType` => `s.property.array`
107+
- `ObjectType` => `s.property.object`
108+
- `ModelType` => `s.property.model`
136109

137-
Type implementers should provide a corresponding variable or function for each defined type. They can even provide
138-
multiple functions or constants when predefined parameters. (For example, we could define `SStringArray` which would
139-
be a variable similar to `SArray(SString)`.)
110+
Type implementers should provide a corresponding function for each defined type. They can even provide
111+
multiple functions or constants with predefined parameters.
112+
(For example, we could define `s.property.stringArray()` which would be similar to `s.property.array(s.property.string())`.)
140113

141114
```typescript
142-
class Example extends Model<Example>
115+
class Example extends s.model({
116+
foo: s.property.string(),
117+
})
143118
{
144-
foo: string = undefined;
145-
146-
protected SDefinition(): ModelDefinition<Example>
147-
{
148-
return {
149-
foo: SDefine(SString),
150-
};
151-
}
119+
foo: string;
152120
}
153121
```
154122

@@ -208,7 +176,6 @@ const result = model.serializeDiff();
208176
// result = { id: 5, title: "A new title for a new world" }
209177
// if `id` is not defined as the model identifier:
210178
// result = { title: "A new title for a new world" }
211-
212179
```
213180

214181
#### `resetDiff()`
@@ -238,7 +205,6 @@ const result = model.serializeDiff();
238205
// result = { id: 5 }
239206
// if `id` is not defined as the model identifier:
240207
// result = {}
241-
242208
```
243209

244210
#### `save()`
@@ -265,5 +231,4 @@ const result = model.save();
265231
// result = { id: 5, title: "A new title for a new world" }
266232
// if `id` is not defined as the model identifier:
267233
// result = { title: "A new title for a new world" }
268-
269234
```

0 commit comments

Comments
 (0)