You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -106,7 +106,7 @@ class User extends Model {
106
106
107
107
We can set a `defaultValue` for each property which will automatically populate a property on creation.
108
108
109
-
The `defaultValue` can also be a method which returns a dynamic value. This function shares the context of a property instance thus you have access to all the features of the `Prop` class.
109
+
The `defaultValue` can also be a method which returns a dynamic value. This function shares the context of the associated model.
110
110
111
111
```ts
112
112
@prop({
@@ -119,7 +119,7 @@ now: string;
119
119
120
120
Similar to default values, we can set a `fakeValue` for each property, to populate a property with fakes data when calling the `fake()` method.
121
121
122
-
The `fakeValue` can also be a method which returns a dynamic value. This function shares the context of a property instance, thus you have access to all the features of the `Prop` class.
122
+
The `fakeValue` can also be a method which returns a dynamic value. This function shares the context of the associated model.
123
123
124
124
```ts
125
125
@prop({
@@ -132,18 +132,18 @@ today: string;
132
132
133
133
By default, all defined properties are set to `null`. Similar to default and fake value we can set an `emptyValue` option for each property, to automatically replace `null` values.
134
134
135
-
The `emptyValue` can also be a method which returns a dynamic value. Note that this function shares the context of a property instance, thus you have access to all the features of the `Prop` class.
135
+
The `emptyValue` can also be a method which returns a dynamic value. This function shares the context of the associated model.
136
136
137
137
```ts
138
138
@prop({
139
-
fakeValue() { return'' },
139
+
emptyValue() { return'' },
140
140
})
141
141
name: string;
142
142
```
143
143
144
144
### Prop Value Transformation
145
145
146
-
A property can have a custom `getter` and a custom `setter`. These methods all share the context of a property instance, thus you have access to all the features of the `Prop` class.
146
+
A property can have a custom `getter` and a custom `setter`. This function shares the context of the associated model.
147
147
148
148
```ts
149
149
@prop({
@@ -250,14 +250,14 @@ Note that the `commit` method will memorize a serialized data and the `rollback`
250
250
251
251
### Validation
252
252
253
-
RawModel provides a simple mechanism for validating properties.
253
+
RawModel provides a simple mechanism for validating properties. Validators shares the context of the associated model.
254
254
255
255
```ts
256
256
classUserextendsModel {
257
257
@prop({
258
258
validate: [ // property validation setup
259
259
{ // validator recipe
260
-
handler: (v) =>!!v, // [required] validator function
260
+
handler(v) { return!!v }, // [required] validator function
261
261
code: 422, // [optional] error code
262
262
condition() { returntrue }, // [optional] condition which switches the validation on/off
RawModel provides a mechanism for handling property-related errors. The logic is aligned with the validation thus the validation and the error handling can easily be managed in a unified way. This is great because we always deal with validation errors and can thus directly send these errors back to a user in a unified format.
277
+
RawModel provides a mechanism for handling property-related errors. The logic is aligned with the validation thus the validation and the error handling can easily be managed in a unified way. This is great because we always deal with validation errors and can thus directly send these errors back to a user in a unified format. Handlers shares the context of the associated model.
278
278
279
279
```ts
280
280
classUserextendsModel {
281
281
@prop({
282
282
handle: [ // property error handling setup
283
283
{ // handler recipe
284
-
handler: (e) =>e.message==='foo', // [required] errir handler function
284
+
handler(e) { returne.message==='foo' }, // [required] errir handler function
285
285
code: 422, // [optional] error code
286
286
condition() { returntrue }, // [optional] condition which switches the handling on/off
0 commit comments