3.0.13 • Published 5 years ago

type-r v3.0.13

Weekly downloads
83
License
MIT
Repository
github
Last release
5 years ago

master build

Getting started

Type-R is the modern JS data framework to manage complex domain and UI application state. Features:

  • 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.
  • All changes are observable, happens in the scope of transactions, and there's the fine-grained change events system.
  • Validation is performed on the first access to the validation error and never happens twice for unchanged data.
  • 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.
  • 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.

overview

Data layer is defined as a superposition of three kinds of building blocks:

  • Record classes with typed attributes.
  • Ordered collections of records.
  • Stores are records with a set of collections in its attributes used to resolve id-references in JSON.
  • IOEndpoints is an entity encapsulating I/O transport which represent the persistent collection of records.

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.

import { define, Record } from 'type-r'

// Define email attribute type with encapsulated validation check.
const Email = String.has.check( x => x! || x.indexOf( '@' ) >= 0, 'Invalid email' );

@define class User extends Record {
    static attributes = {
        name  : String.isRequired, // should not be empty for the record to be valid.
        email : Email.isRequired
    }
}

@define class Message extends Record {
    static attributes = {
        created : Date //  = new Date()
        author  : User, // aggregated User record.
        to      : User.Collection, // aggregating collection of users
        subject : '',
        body    : ''
    }
}

const msg = new Message();
assert( !msg.isValid() ); // Is not valid because msg.author has empty attributes

// Listen for the changes in aggregation tree...
msg.on( 'change', () => console.log( 'change!!!' ) );

msg.transaction( () => { // Prepare to make the sequence of changes on msg
    msg.author.name = 'John Dee'; // No 'change' event yet as we're in the transaction. 
    msg.author.email = 'dee@void.com'; 

    assert( msg.isValid() ); // Now msg is valid as all of its attributes are valid.
}); // Got single 'change!!!' message in the console.

Documentation

Installation and requirements

Is packed as UMD and ES6 module. No peer dependencies are required.

npm install type-r --save-dev

3.0.13

5 years ago

3.0.12

5 years ago

3.0.11

5 years ago

3.0.10

5 years ago

3.0.9

5 years ago

3.0.8

5 years ago

3.0.1

5 years ago

3.0.0-a06

5 years ago

3.0.0-a05

6 years ago

3.0.0-a04

6 years ago

3.0.0-a03

6 years ago

3.0.0-a02

6 years ago

3.0.0-a01

6 years ago

3.0.0

6 years ago

2.1.8

6 years ago

2.1.7

6 years ago

2.1.6

6 years ago

2.1.5

6 years ago

2.1.4

6 years ago

2.1.3

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.10

6 years ago

2.0.9

6 years ago

2.0.8

6 years ago

2.0.7

6 years ago

2.0.6

6 years ago

2.0.5

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

2.0.0-rc05

7 years ago

2.0.0-rc04

7 years ago

2.0.0-rc03

7 years ago

2.0.0-rc02

7 years ago

2.0.0-rc01

7 years ago

1.1.0-a20

7 years ago

1.1.0-a19

7 years ago

1.1.0-a18

7 years ago

1.1.0-a17

7 years ago

1.1.0-a16

7 years ago

1.1.0-a15

7 years ago

1.1.0-a14

7 years ago

1.1.0-a13

7 years ago

1.1.0-a12

7 years ago

1.1.0-a11

7 years ago

1.1.0-a10

7 years ago

1.1.0-a09

7 years ago

1.0.4

7 years ago

1.1.0-a08

7 years ago

1.1.0-a07

7 years ago

1.1.0-a06

7 years ago

1.1.0-a05

7 years ago

1.1.0-a04

7 years ago

1.1.0-a03

7 years ago

1.1.0-a02

7 years ago

1.1.0-a00

7 years ago

1.1.0

7 years ago

1.0.3

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

1.0.0-rc991

7 years ago

1.0.0-rc990

7 years ago

1.0.0-rc99

7 years ago

1.0.0-rc98

7 years ago

1.0.0-rc97

7 years ago

1.0.0-rc96

7 years ago

1.0.0-rc95

7 years ago

1.0.0-rc94

7 years ago

1.0.0-rc93

7 years ago

1.0.0-rc92

7 years ago

1.0.0-rc91

7 years ago

1.0.0-rc9

7 years ago

1.0.0-rc6

8 years ago

1.0.0-rc4

8 years ago

1.0.0-rc3

8 years ago

1.0.0-rc2

8 years ago

1.0.0-rc1

8 years ago

1.0.0-b02

8 years ago

1.0.0-b01

8 years ago

1.0.0-a20

8 years ago

1.0.0-a19

8 years ago

1.0.0-a18

8 years ago

1.0.0-a17

8 years ago

1.0.0-a16

8 years ago

1.0.0-a15

8 years ago

1.0.0-a14

8 years ago

1.0.0-a13

8 years ago

1.0.0-a12

8 years ago

1.0.0-a11

8 years ago

1.0.0-a10

8 years ago

1.0.0-a09

8 years ago

1.0.0-a08

8 years ago

1.0.0-a07

8 years ago

1.0.0-a06

8 years ago

1.0.0-a05

8 years ago

1.0.0-a04

8 years ago

1.0.0-a03

8 years ago

1.0.0-a02

8 years ago

1.0.0-a01

8 years ago

0.1.2-92

8 years ago

0.1.2-91

8 years ago

0.1.2-90

8 years ago

0.1.2-9

8 years ago

0.1.2-8

8 years ago

0.1.2-7

8 years ago

0.1.2-6

8 years ago

0.1.2-5

8 years ago

0.1.2-4

8 years ago

0.1.2-3

8 years ago

0.1.2-2

8 years ago

0.1.2-1

8 years ago

0.1.2-0

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago

1.0.0-1

8 years ago