Skip to content

Commit adbe643

Browse files
author
Vlad Balin
committed
Updated front page
1 parent 3b9444a commit adbe643

File tree

4 files changed

+73
-41
lines changed

4 files changed

+73
-41
lines changed

README.md

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,73 @@
44

55
# Getting started
66

7-
Type-R helps to declaratively define complex domain and UI application state in modern JS applications as a superposition of three kinds of building blocks:
7+
Type-R is the modern JS data framework allowing declaratively definitions of complex domain and UI application state. The state is defined as the superposition of JS classes extending `Record` and `Collection`, and has following features:
8+
9+
- _It's mapped to JSON by default_. The mapping can handle sophisticated scenarios with nested JSON and relations by id, and can be easily customized for every particular attribute or class.
10+
- _All changes are observable_, happens in the scope of transactions, and there's the fine-grained change events system.
11+
- _Validation_ is performed on the first access to the validation error and never happens twice for unchanged data.
12+
- _Everything is typed at run-time_ and is protected from improper updates. The shape of generated JSON and data classes is guaranteed to match the definitions.
13+
- It still looks like regular JS classes and is freaking fast. Type-R data structures are about 10 times faster than Backbone models and collections.
14+
15+
![overview](docs/images/overview.png)
16+
17+
Data layer is defined as a superposition of three kinds of building blocks:
818

919
- *Record* classes with typed attributes.
1020
- Ordered *collections* of records.
11-
- *Stores* to hold collections used to resolve id-references in JSON.
21+
- *Stores* are records with a set of collections in its attributes used to resolve id-references in JSON.
1222

13-
The state defined with Type-R classes is deeply observable and serializable by default. While being an advanced JSON serialization engine handling sophisticated scenarios (like cross-collections many-to-many relationships), Type-R is completely unopinionated on the client-server transport protocol.
23+
Type-R is completely unopinionated on the client-server transport protocol and the view layer technology. It's your perfect M and VM in modern MVVM or MVC architecture.
1424

15-
Type-R is your perfect M and VM in MVVM and MVC architecture imposing no restrictions on V and C parts.
25+
```javascript
26+
import { define, Record } from 'type-r'
1627

17-
API docs site: https://volicon.github.io/Type-R/
28+
// Define email attribute type with encapsulated validation check.
29+
const Email = String.has.check( x => x! || x.indexOf( '@' ) >= 0, 'Invalid email' );
1830

19-
## Installation and requirements
31+
@define class User extends Record {
32+
static attributes = {
33+
name : String.isRequired, // should not be empty for the record to be valid.
34+
email : Email.isRequired
35+
}
36+
}
2037

21-
Is packed as UMD and ES6 module. No peer dependencies are required.
38+
@define class Message extends Record {
39+
static attributes = {
40+
created : Date // = new Date()
41+
author : User, // aggregated User record.
42+
to : User.Collection, // aggregating collection of users
43+
subject : '',
44+
body : ''
45+
}
46+
}
2247

23-
`npm install type-r --save-dev`
48+
const msg = new Message();
49+
assert( !msg.isValid() ); // Is not valid because msg.author has empty attributes
2450

25-
<aside class="success">IE10+, Edge, Safari, Chrome, and Firefox are supported</aside>
51+
// Listen for the changes in aggregation tree...
52+
msg.on( 'change', () => console.log( 'change!!!' ) );
2653

27-
<aside class="warning">IE9 and Opera may work but has not been tested. IE8 won't work.</aside>
54+
msg.transaction( () => { // Prepare to make the sequence of changes on msg
55+
msg.author.name = 'John Dee'; // No 'change' event yet as we're in the transaction.
56+
msg.author.email = '[email protected]';
2857

29-
## How the Type-R compares with X?
58+
assert( msg.isValid() ); // Now msg is valid as all of its attributes are valid.
59+
}); // Got single 'change!!!' message in the console.
60+
```
3061

31-
Type-R started to develop in 2014 as the modern substitution for BackboneJS, which would retain the spirit of the BackboneJS simplicity but would be superior to Ember Data in its capabilities and an order of magnitude faster than Backbone.
3262

33-
The closest things to the Type-R are [Ember Data](https://guides.emberjs.com/v2.2.0/models/), [BackboneJS models and collections](http://backbonejs.org/#Model), and [mobx](https://github.com/mobxjs/mobx).
63+
## [Documentation](https://volicon.github.io/Type-R/)
3464

35-
There are a lot of similarities:
65+
## Installation and requirements
3666

37-
- All that things can be used to manage an application's state.
38-
- Type-R handles observable transactional changes in the way more or less similar to mobx (however, it's heavily optimized for the case of large aggregated object trees).
39-
- Type-R id-relationships and validation capabilities are comparable to ones in [Ember Data](https://guides.emberjs.com/v2.2.0/models/relationships/), which was used a source of inspiration.
40-
- Type-R has a lot of common in some API parts with BackboneJS models and collections. For instance, it uses the close API for the [collection updates](#update) and the [similar event model](#built-in-events) for the changes (however, it's generalized for the case of transactions on the nested records and collections).
67+
Is packed as UMD and ES6 module. No peer dependencies are required.
4168

42-
Speaking of the distinguishing differences,
69+
`npm install type-r --save-dev`
4370

44-
- Type-R's records are not key-value pairs but _classes_ with typed attributes. They are protected from improper assignment with run-time type assertions and conversions. Which means that the client-server protocol is protected again errors from both ends.
45-
- Type-R distinguishes aggregation and the plain association operating with _aggregation trees_ formed by nested records and collections. Aggregation tree is serialized as nested JSON. Operations like `clone()`, `dispose()`, `isValid()` and `toJSON()` are performed recursively on elements of aggregation tree gracefully handling the references to shared objects.
46-
- Type-R relies on _layered application state_ instead of the global singleton store. In Type-R, the stores are the special kind of records which can participate in dynamically configured lookup chains. There might be as many dynamically created and disposed stores as you need, starting with no stores at all.
47-
- Type-R features automatic lazily evaluated [validation](#validation) with declarative attribute-level rules. Validation checks are the part of the attribute type; they are evaluated in the moment they needed and never performed twice on the unchanged data.
48-
- Type-R is really fast. It's capable of handling collections of 10K elements with real-time response and is about 10 times faster than BackboneJS.
71+
<aside class="success">IE10+, Edge, Safari, Chrome, and Firefox are supported</aside>
4972

50-
Feature | Type-R | Backbone Models | Ember Data | mobx
51-
-|-|-|-|-
52-
Observable changes in object graph | ✓ | - | - | ✓
53-
JSON Serialization | ✓ | ✓ | ✓ | -
54-
Validation | ✓ | ✓ | ✓ | -
55-
Dynamic Type Safety | ✓ | - | For serialization only | -
56-
Aggregation | ✓ | - | - | -
57-
Relations by id | ✓ | - | ✓ | -
73+
<aside class="warning">IE9 and Opera may work but has not been tested. IE8 won't work.</aside>
5874

5975
## Roadmap
6076

docs/images/overview.png

58.1 KB
Loading

docs/index.html

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,22 @@
7373
<div class="page-wrapper">
7474
<div class="content">
7575
<h1 id="getting-started">Getting started</h1>
76-
<p>Type-R helps to declaratively define complex domain and UI application state in modern JS applications as a superposition of three kinds of building blocks:</p>
76+
<p>Type-R is the modern JS data framework allowing declaratively definitions of complex domain and UI application state. The state is defined as the superposition of JS classes extending <code>Record</code> and <code>Collection</code>, and has following features:</p>
77+
<ul>
78+
<li><em>It&#39;s mapped to JSON by default</em>. The mapping can handle sophisticated scenarios with nested JSON and relations by id, and can be easily customized for every particular attribute or class.</li>
79+
<li><em>All changes are observable</em>, happens in the scope of transactions, and there&#39;s the fine-grained change events system.</li>
80+
<li><em>Validation</em> is performed on the first access to the validation error and never happens twice for unchanged data.</li>
81+
<li><em>Everything is typed at run-time</em> and is protected from improper updates. The shape of generated JSON and data classes is guaranteed to match the definitions.</li>
82+
<li>It still looks like regular JS classes and is freaking fast. Type-R data structures are about 10 times faster than Backbone models and collections.</li>
83+
</ul>
84+
<p><img src="images/overview.png" alt="overview"></p>
85+
<p>Data layer is defined as a superposition of three kinds of building blocks:</p>
7786
<ul>
7887
<li><em>Record</em> classes with typed attributes.</li>
7988
<li>Ordered <em>collections</em> of records.</li>
80-
<li><em>Stores</em> to hold collections used to resolve id-references in JSON.</li>
89+
<li><em>Stores</em> are records with a set of collections in its attributes used to resolve id-references in JSON.</li>
8190
</ul>
82-
<p>The state defined with Type-R classes is deeply observable and serializable by default. While being an advanced JSON serialization engine handling sophisticated scenarios (like cross-collections many-to-many relationships), Type-R is completely unopinionated on the client-server transport protocol.</p>
83-
<p>Type-R is your perfect M and VM in MVVM and MVC architecture imposing no restrictions on V and C parts.</p>
91+
<p>Type-R is completely unopinionated on the client-server transport protocol and the view layer technology. It&#39;s your perfect M and VM in modern MVVM or MVC architecture.</p>
8492
<pre><code class="highlight javascript"><span class="hljs-keyword">import</span> { define, Record } <span class="hljs-keyword">from</span> <span class="hljs-string">'type-r'</span>
8593

8694
<span class="hljs-comment">// Define email attribute type with encapsulated validation check.</span>

docs/index.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,23 @@ search: true
1818

1919
# Getting started
2020

21-
Type-R helps to declaratively define complex domain and UI application state in modern JS applications as a superposition of three kinds of building blocks:
21+
Type-R is the modern JS data framework allowing declaratively definitions of complex domain and UI application state. The state is defined as the superposition of JS classes extending `Record` and `Collection`, and has following features:
22+
23+
- _It's mapped to JSON by default_. The mapping can handle sophisticated scenarios with nested JSON and relations by id, and can be easily customized for every particular attribute or class.
24+
- _All changes are observable_, happens in the scope of transactions, and there's the fine-grained change events system.
25+
- _Validation_ is performed on the first access to the validation error and never happens twice for unchanged data.
26+
- _Everything is typed at run-time_ and is protected from improper updates. The shape of generated JSON and data classes is guaranteed to match the definitions.
27+
- It still looks like regular JS classes and is freaking fast. Type-R data structures are about 10 times faster than Backbone models and collections.
28+
29+
![overview](images/overview.png)
30+
31+
Data layer is defined as a superposition of three kinds of building blocks:
2232

2333
- *Record* classes with typed attributes.
2434
- Ordered *collections* of records.
25-
- *Stores* to hold collections used to resolve id-references in JSON.
26-
27-
The state defined with Type-R classes is deeply observable and serializable by default. While being an advanced JSON serialization engine handling sophisticated scenarios (like cross-collections many-to-many relationships), Type-R is completely unopinionated on the client-server transport protocol.
35+
- *Stores* are records with a set of collections in its attributes used to resolve id-references in JSON.
2836

29-
Type-R is your perfect M and VM in MVVM and MVC architecture imposing no restrictions on V and C parts.
37+
Type-R is completely unopinionated on the client-server transport protocol and the view layer technology. It's your perfect M and VM in modern MVVM or MVC architecture.
3038

3139
```javascript
3240
import { define, Record } from 'type-r'

0 commit comments

Comments
 (0)