Tweaks
This commit is contained in:
parent
3ef314bc21
commit
4c61507658
|
@ -208,12 +208,15 @@ for the type definitions above is the following:
|
|||
|
||||
```preserves
|
||||
version 1 .
|
||||
|
||||
BookOutline = {
|
||||
"sections": @sections [BookItem ...],
|
||||
} .
|
||||
|
||||
BookItem = @chapter { "Chapter": @value Chapter }
|
||||
/ @separator "Separator"
|
||||
/ @partTitle { "PartTitle": @value string } .
|
||||
|
||||
Chapter = {
|
||||
"name": @name string,
|
||||
"sub_items": @sub_items [BookItem ...],
|
||||
|
@ -242,11 +245,13 @@ Using the TypeScript schema compiler, we see
|
|||
|
||||
```typescript
|
||||
export type BookOutline = {"sections": Array<BookItem>};
|
||||
|
||||
export type BookItem = (
|
||||
{"_variant": "chapter", "value": Chapter} |
|
||||
{"_variant": "separator"} |
|
||||
{"_variant": "partTitle", "value": string}
|
||||
);
|
||||
|
||||
export type Chapter = {"name": string, "sub_items": Array<BookItem>};
|
||||
```
|
||||
|
||||
|
@ -255,9 +260,9 @@ Using the Racket schema compiler, we see
|
|||
```racket
|
||||
(struct BookOutline (sections))
|
||||
(define (BookItem? p)
|
||||
(or (BookItem-chapter? p)
|
||||
(BookItem-separator? p)
|
||||
(BookItem-partTitle? p)))
|
||||
(or (BookItem-chapter? p)
|
||||
(BookItem-separator? p)
|
||||
(BookItem-partTitle? p)))
|
||||
(struct BookItem-chapter (value))
|
||||
(struct BookItem-separator ())
|
||||
(struct BookItem-partTitle (value))
|
||||
|
@ -281,8 +286,7 @@ BookItem = Chapter / =separator / @partTitle string .
|
|||
Chapter = <chapter @name string @sub_items [BookItem ...]> .
|
||||
```
|
||||
|
||||
The schema compilers produce **exactly the same** type definitions for this variation!
|
||||
|
||||
The schema compilers produce **exactly the same** type definitions for this variation.
|
||||
The differences are in the (de)serialization code only.
|
||||
|
||||
Here's the Preserves value equivalent to the example above, expressed using the Preserves-native schema:
|
||||
|
|
Loading…
Reference in New Issue