Mixin: NestedDirtyModel

NestedDirtyModel

Adds the $dirty method to a model`s instances. Acts in the same way as the DirtyModel plugin, but supports nested objects.

Source:
  • plugins/nested-dirty.js, line 1

Methods

$dirty(_prop, _comparator) → {boolean|array}

Retrieves the model changes

Property changes are determined using the strict equality operator if no comparator function is provided.

If given a property name, this method will return true if property has changed or false if it has not.

The comparator function can be passed either as the first or second parameter. If first, this function will compare all properties using the comparator.

Called without arguments, this method will return a list of changed property names.

Parameters:
Name Type Description
_prop string | function

Property to query or function to compare all properties

_comparator function

Function to compare property

Source:
  • plugins/nested-dirty.js, line 97
Returns:

Property state or array of changed properties

Type
boolean | array

$restore(_prop) → {Model}

Restores the model's last fetched values.

Usage:

bike = Bike.$create({ brand: 'Trek' });
// later on...
bike.brand = 'Giant';
bike.$restore();

console.log(bike.brand); // outputs 'Trek'
Parameters:
Name Type Description
_prop string

If provided, only _prop is restored

Source:
  • plugins/nested-dirty.js, line 128
Returns:

self

Type
Model