-
-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathconstants.ts
39 lines (37 loc) · 1.1 KB
/
constants.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import primitive from "./types/primitive"
/**
* If you want to skip serialization or deserialization, you can use SKIP.
*
* @example
* const schema = createSimpleSchema({
* a: custom(
* () => SKIP,
* v => v,
* ),
* })
* serialize(s, { a: 4 }) // {}
* deserialize(s, { "a": 4 }) // { a: 4 }
*
* @example
* // Skipping deserialization with computed mobx property.
*
* class TodoState {
* // Todo.category is @serializable(reference(...))
* @serializable(list(object(Todo)))
* @observable
* todos: Todo[]
*
* // we want to serialize the categories, so that the references in
* // this.todos can be resolved, but we don't want to set this property
* @serializable(
* list(object(TodoCategory),
* { afterDeserialize: callback => callback(undefined, SKIP) }))
* @computed
* get categories() {
* return this.todos.map(todo => todo.category)
* }
* }
*/
export const SKIP = typeof Symbol !== "undefined" ? Symbol("SKIP") : { SKIP: true }
export type SKIP = typeof SKIP
export const _defaultPrimitiveProp = primitive()