Skip to content

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

License

Notifications You must be signed in to change notification settings

DagonMetric/ng-entity-change-checker

Repository files navigation

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.