@sky-js/storex
v2.0.0-rc-6
Published
Centralized Store Management
Downloads
4
Readme
storex
Centralized Store Management
Model
// author.model.ts
class Author extends Model
{
@attribute()
id? : number;
@attribute()
name? : string;
}
// booksa.ts
class Booksa extends Model
{
@attribute()
id? : number;
@attribute()
name? : string;
@hasOne()
author? : AuthorModel
}
Collection
// book.collection.ts
import {Collection} from "./collection";
class BookCollection extends Collection
{
}
// author.collection.ts
class AuthorCollection extends Collection
{
}
Validation Rule
class Comment extends Model {
attributes() {
return {
id: null,
user_id : null,
message: null,
}
},
rule() {
return {
id: [
{type: 'integer'},
{type: 'required},
],
user_id: [
{type: 'integer'},
{type: 'required'}
],
message: [
{type: 'string', min: 5, max: 100},
]
}
}
}
Usage
import {AuthorModel} from "./author.model";
const author = new AuthorModel({name: 'JK Rowling'});
console.log(author.name); // JK Rowling
author.name = 'Jason Mayer'
console.log(author.name); // Jason Mayer
author.reset();
console.log(author.name) // JK Rowling