Skip to content

SharangUkidve/clonedeep-decorator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CloneDeep Decorator

A simple decorator function that uses lodash's cloneDeep function to set and retrieve a deep cloned value.

Note: The getter also returns a deep clone to avoid mutations to the original value.

npm i clonedeep-decorator

yarn add clonedeep-decorator

Usage

class MyFormComponent {
  formState: any;

  @CloneDeep() originalFormState: any;

  async getFormData() {
    this.formState = await (await fetch('example/api')).json();

    // Original Will Be A deepClone of the json
    this.originalFormState = this.formState;
  }

  resetFormState() {
    // formState will receive a fresh deepClone to avoid mutations to original
    this.formState = this.originalFormState;
  }
}

Dependencies

lodash.clonedeep is a required dependency for the CloneDeep decorator.

npm i lodash.clonedeep^4.5.0

yarn add lodash.clonedeep^4.5.0

About

Decorator to set deep clone and retrieve deep cloned objects

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published