https://github.com/rockman84/storex
Centralized Store Management
https://github.com/rockman84/storex
js model storex typescript
Last synced: about 2 months ago
JSON representation
Centralized Store Management
- Host: GitHub
- URL: https://github.com/rockman84/storex
- Owner: rockman84
- License: gpl-3.0
- Created: 2020-11-07T14:06:03.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-08-31T08:48:24.000Z (over 2 years ago)
- Last Synced: 2025-03-01T00:25:09.434Z (3 months ago)
- Topics: js, model, storex, typescript
- Language: JavaScript
- Homepage:
- Size: 483 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# storex
Centralized Store Management### Model
``` typescript
// 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
```typescript
// book.collection.ts
import {Collection} from "./collection";class BookCollection extends Collection
{
}// author.collection.ts
class AuthorCollection extends Collection
{
}
```### Validation Rule
```typescript
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
```typescript
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 Mayerauthor.reset();
console.log(author.name) // JK Rowling```