2.0.0-rc-6 • Published 2 years ago

@sky-js/storex v2.0.0-rc-6

Weekly downloads
-
License
GPL-3.0-or-later
Repository
github
Last release
2 years ago

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
2.0.0-rc-5

2 years ago

2.0.0-rc-6

2 years ago

2.0.0-rc-1

2 years ago

2.0.0-rc-2

2 years ago

2.0.0-rc-3

2 years ago

2.0.0-rc-4

2 years ago

2.0.0-alpha-6

2 years ago

2.0.0-alpha-7

2 years ago

2.0.0-alpha-2

2 years ago

2.0.0-alpha-4

2 years ago

2.0.0-alpha-5

2 years ago

1.0.0

3 years ago