@dagonmetric/ng-entity-change-checker
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Entity Change Checker for Angular

Azure Pipelines Status GitHub Actions Status

Object dirty checker and change states (such as Added, Modified or Deleted) and modified properties detector service for Angular applications.

Get Started

Installation

npm

npm install @dagonmetric/ng-entity-change-checker

or yarn

yarn add @dagonmetric/ng-entity-change-checker

Latest npm package is npm version

Module Setup (app.module.ts)

import { EntityChangeCheckerModule } from '@dagonmetric/ng-entity-change-checker';

@NgModule({
  imports: [
    // Other module imports

    // ng-entity-change-checker module
    EntityChangeCheckerModule    
  ]
})
export class AppModule { }

Usage (app.component.ts)

import { Component } from '@angular/core';

import { EntityChangeChecker } from '@dagonmetric/ng-entity-change-checker';


@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']  
})
export class AppComponent {
  constructor(private readonly entityChangeChecker: EntityChangeChecker) {
    const sourceObj: MyType = {
        prop1: 'hello',
        prop2: 500,
        prop3: false,
        trackingState: TrackingState.Unchanged,
        modifiedProperties: []
    };

    const modObj = JSON.parse(JSON.stringify(sourceObj)) as MyType;
    modObj.prop1 = 'my';
    modObj.prop3 = true;               

    const isDirty = entityChangeChecker.checkChanges(modObj, sourceObj);
    console.log('isDirty: ', isDirty); // Output: true
    console.log('trackingState: ', modObj.trackingState); // Output: 2
    console.log('modifiedProperties: ', modObj.modifiedProperties); // Output: ['prop1', 'prop3']
  }
}

Feedback and Contributing

Check out the Contributing page.

License

This repository is licensed with the MIT license.

Package Sidebar

Install

npm i @dagonmetric/ng-entity-change-checker

Weekly Downloads

2

Version

1.0.2

License

MIT

Unpacked Size

104 kB

Total Files

28

Last publish

Collaborators

  • mmzliveid
  • dagonmetric-contributor