Skip to content

Commit b41ef76

Browse files
committed
more docs
1 parent a38fc5f commit b41ef76

File tree

10 files changed

+107
-6
lines changed

10 files changed

+107
-6
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ async function run () {
4040
const {StructType, T} = realm;
4141

4242
const Point = new StructType(
43-
'Point',
4443
{
4544
r: T.UInt8,
4645
g: T.UInt8,
@@ -54,16 +53,16 @@ async function run () {
5453
}
5554
);
5655

57-
const Column = new StructType('Column', Point, 1024);
56+
const Column = new StructType(Point, 1024);
5857

59-
const Screen = new StructType('Screen', Column, 768);
58+
const Screen = new StructType(Column, 768);
6059

6160

6261
const display = new Screen();
6362

6463
display[10][10].r = 127;
6564

66-
const User = new StructType('User', {
65+
const User = new StructType({
6766
name: T.String,
6867
screen: Screen.ref // Store references to screens, don't embed them
6968
});

src/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
* [Builtin Types](./builtins/README.md)
44
* [Hash Functions](./hash-functions/README.md)
5-
* [Type Classes](./type-classes/README.md)
5+
* [Type Classes](./type-class/README.md)
66
* [String Pool](./string-pool/README.md)

src/type-class/README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
# Type Classes
22

3-
Type classes represent categories of type. Each type class is assigned a range of possible ids, and each instantiation of a type class (a Type), has an id within that range.
3+
Type classes represent categories of type. Each type class is assigned a range of possible ids, and each instantiation of a type class (a Type), has an id within that range.
4+
5+
Builtin Type Classes:
6+
7+
* [ArrayType](./array-type/README.md)
8+
* [HashMapType](./hash-map-type/README.md)
9+
* [ObjectType](./object-type/README.md)
10+
* [PrimitiveType](./primitive-type/README.md)
11+
* [ReferenceType](./reference-type/README.md)
12+
* [StringType](./string-type/README.md)
13+
* [StructType](./struct-type/README.md)

src/type-class/array-type/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# ArrayType
2+
3+
Type class for fixed length typed arrays. Takes another Type as input and produces an array type for it.
4+
5+
Usage:
6+
7+
```js
8+
const {ArrayType, T} = realm;
9+
const NumberArray = new ArrayType(T.Float64);
10+
11+
const numbers = new NumberArray(3);
12+
13+
numbers[0] === 0;
14+
numbers[1] === 0;
15+
numbers[2] === 0;
16+
17+
numbers[1] = 123;
18+
19+
numbers.forEach(num => console.log(num));
20+
21+
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# HashMapType
2+
3+
A type class for typed hash maps. Takes a key type and a value type as input and produces a hash map type which can store key / values of those types.
4+
5+
Usage:
6+
7+
```js
8+
const {HashMapType, T} = realm;
9+
10+
const StringMap = new HashMapType(T.String, T.String);
11+
12+
const map = new StringMap();
13+
14+
map.set('hello', 'world');
15+
16+
console.log(map.get('hello'));
17+
```

src/type-class/object-type/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# ObjectType
2+
3+
A type class for typed objects. See [T.Object](../../builtins/object/README.md) for more information.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# PrimitiveType
2+
3+
A type class for primitive types such as numbers, booleans etc.
4+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# ReferenceType
2+
3+
A type class for representing references to instances of other types. Takes a single Type as input and returns a new type which can store references to values of the given type.
4+

src/type-class/string-type/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# StringType
2+
3+
A type class for different kinds of [string](../../builtins/string/README.md).

src/type-class/struct-type/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# StructType
2+
3+
A type class which can create object types with fixed layouts. Takes an object or array of fields as input and produces a type which can store objects with that shape.
4+
5+
Usage:
6+
7+
```js
8+
const {StructType, T} = realm;
9+
10+
const Thing = new StructType({
11+
name: T.String
12+
});
13+
14+
const User = new StructType({
15+
name: T.String,
16+
likes: Thing.ref.Array
17+
});
18+
19+
const things = new Thing.Array([
20+
{
21+
name: 'Shopping'
22+
},
23+
{
24+
name: 'Eating Cake'
25+
},
26+
{
27+
name: 'Reading'
28+
},
29+
{
30+
name: 'Football'
31+
}
32+
]);
33+
34+
const alice = new User({
35+
name: 'Alice',
36+
likes: [things[0], things[1], things[2]]
37+
});
38+
39+
console.log(alice.likes[0].name);
40+
```

0 commit comments

Comments
 (0)