@aegis-techno/ngx-entity-manager

Entity manager for Angular App.

Usage no npm install needed!

<script type="module">
  import aegisTechnoNgxEntityManager from 'https://cdn.skypack.dev/@aegis-techno/ngx-entity-manager';
</script>

README

ngx-entity-manager

An Angular entity manage.

Installation

Install via npm:

npm install @aegis-techno/ngx-entity-manager --save

Install manually:

  • Add @aegis-techno/ngx-entity-manager into package.json.
  • Run npm install.

Usage

import {NgxEntity, NgxAbstractEntity, NgxRelation} from '@aegis-techno/ngx-entity-manager';
import {forwardRef} from '@angular/core';

@NgxEntity()
export class MyObject extends NgxAbstractEntity<string> { 
    public name: string = null;

    @NgxRelation(forwardRef(() => MyObjectChild))
    public oneChild: MyObjectChild= null;

    @NgxRelation(forwardRef(() => MyObjectChild), true)
    public arrayChild: Array<MyObjectChild2> = null;
}

@NgxEntity()
export class MyObjectChild extends NgxAbstractEntity<string> { 
    public name = null
}

export class MyObjectChild2 extends MyObjectChild { 
    public name2 = null
}



API

NgxAbstractEntity

Methods

  • fromObject(object: any): NgxAbstractEntity<T>: Return instance of object and save it.
  • findById(id: any): NgxAbstractEntity<T>: Return instance of object if a saved item has this id.
Example

const myObject = MyObject.fromObject({
                                         id: '1',
                                         name: 'myObjectName',
                                         oneChild: {
                                             id: '1',
                                             name: 'myObjectChildName'
                                         },
                                         arrayChild: [
                                             {
                                                 id: '2',
                                                 name: 'myObjectChildName',
                                                 name2: 'myObjectChild2Name'
                                             },
                                             {
                                                 id: '3',
                                                 name: 'myObjectChildName',
                                                 name2: 'myObjectChild2Name'
                                             }
                                         ]
                                     });

const myObjectChild = MyObjectChild.findById<MyObjectChild>('1');
const myObjectChild2 = MyObjectChild2.findById<MyObjectChild2>('2');