Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Molstar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michal Malý
Molstar
Commits
050edf26
Commit
050edf26
authored
7 years ago
by
David Sehnal
Browse files
Options
Downloads
Patches
Plain Diff
tweaked docs
parent
c2a140b7
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docs/cif-schemas.md
+16
-3
16 additions, 3 deletions
docs/cif-schemas.md
with
16 additions
and
3 deletions
docs/cif-schemas.md
+
16
−
3
View file @
050edf26
...
...
@@ -15,6 +15,12 @@ This is obviously not strongly typed + the "fields" dont know what type they are
type
FieldSchema
<
T
>
=
{
T
:
T
/* remember the type */
,
createColumn
:
CIFField
=>
Column
<
T
>
}
```
where column is just a function that for a given row returns a value of
``T``
:
```
ts
type
Column
<
T
>
=
(
row
:
number
)
=>
T
```
Category schema is just an object whose properties are all instances of "field schemas", its "shape" has the type:
```
ts
...
...
@@ -25,8 +31,8 @@ We can declare our first category "schema":
```
ts
const
my_category
=
{
num_field
:
{
T
:
0
as
number
,
createColumn
:
f
=>
Column
(
f
=>
f
.
getNumber
)
}
str_field
:
{
T
:
''
as
string
,
createColumn
:
f
=>
Column
(
f
=>
f
.
getString
)
}
num_field
:
{
T
:
0
as
number
,
createColumn
:
f
=>
f
.
getNumber
}
str_field
:
{
T
:
''
as
string
,
createColumn
:
f
=>
f
.
getString
}
}
```
...
...
@@ -50,12 +56,19 @@ function toTypedCategory<Schema extends CategorySchema>(schema: Schema, category
const
field
=
category
(
key
);
typedCategory
[
key
]
=
field
?
schema
[
key
].
createFolumn
(
field
)
:
UndefinedColumn
;
// a column that always returns 0 or empty string depending on type
:
UndefinedColumn
(
schema
[
key
].
T
)
;
// a column that always returns 0 or empty string depending on type
}
return
typedCategory
;
}
```
This transforms the ''untyped''
``Category``
to some typed category and gives us code-completion for CIF files:
```
ts
const
typed
=
toTypedCategory
(
my_category
,
...);
typed
.
n
/* shows code completion for num_field */
```
And that's all there is to it. Extending the types to the "block" level is left as an exercise to the reader.
----------------
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment