ChangeChecker API - HohensteinGroup/ChangeChecker GitHub Wiki

ChangeChecker API Documentation

This document describes the "ChangeChecker" API in more detail, including limitations and edge cases.

From now on I will distinguish between three different data structures:

  • arrays
  • objects
  • values (strings, numbers, null etc.)
  • "value likes" (Objects who behave like values e.g. decimal.js)

takeSnapshot

This method simply builds up a clone by recursing through the input object while maintaining a map of previously visited references in order to avoid infinitely traversing cycles.

  • Properties of type 'Function' and "__" (double underscore) prefixed properties get ignored.
  • The prototype chain does get walked but not duplicated (the clone owns all properties).
  • Property descriptors, setters, and getters (as well as similar metadata-like features) are not duplicated.
  • If a plugin matches for any node of the incoming object (via "isMatch") the provided "clone" method gets called to obtain the copy. This is where you start if parts of your model contain logic that should not be stripped out or the prototype is important.

Important note: The input object and all it's childs will be associated with a unique "objectId" using symbols (MDN)! This is how "createDiff" will match the corresponding objects of the snapshot and the model later on.

createDiff

This method transforms the incoming data to the following three structures:

  • ObjectDiff
    • PropertyDiff
  • ArrayDiff

see "Diff structures"

withPlugin

To extend change-checker, add plugins described here.