# Module: documents/binder

## documents/binder

allows you to bind a change watcher that looks for get and set operations on an arbitrary property of an object at at any depth. This allows you to look for changes or intercept values asynchronously or otherwise.

Source:
  - documents/binder.js, line 2

### Requires

- module:async
- module:documents/probe
- module:lodash
- module:promise

### Methods

#### <static> bind(path, record, options) → {*}

  Bind to a property somewhere in an object. The property is found using dot notation and can be arbitrarily deep.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `path` | string | The path into the object to locate the property. For instance this could be `"_id"`, `"name.last"`. or `"some.really.really.long.path.including.an.array.2.name"`
  `record` | object | Anything you can hang a property off of

  `options`

  options

  What you wanna do with the doohicky when yoyu bind it.

  ###### Properties

  Name | Type | Argument | Description
  --- | --- | --- | ---

  `getter`

  function

  This is the method to run when getting the value. When it runs, you will receive a single parameter which is the current value as the object understands it. You can return the value directly, just raise an event or whatever your little heart demands. However, if you are asynchronous, this will turn your return value into a promise, one of the few places this system will embrace promises over node-like error passing and that is mainly because this is a getter so a return value is particularly important. *

  ###### Properties

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `value` | * |  | The current value of the record
  `callback` | function | <optional> | When asynchronous, return you value through this method using node style error passing (the promise is handled for you by this method).

  `getterAsync` | boolean | <optional> | When true (not truthy) the getter is treated asynchronously and returns a promise with your value.

  `setter`

  function

  <optional>

  A setter method

  ###### Properties

  Name | Type | Description
  --- | --- | ---
  `newVal` | * | The new value
  `oldVal` | * | The old value
  `record` | * | The record hosting the change

  `validator`

  function

  <optional>

  If you want a validator to run before settings values, pass this guy in

  ###### Properties

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `newVal` | * |  | The new value
  `oldVal` | * |  | The old value
  `record` | * |  | The record hosting the change
  `callback` | function | <optional> | If the validator is asynchronous, then pass your value back here, otherwise pass it back as a return value. When you use an asynchronous instance, pass the error in the first value and then the rest of the parameters are yours to play with

  `validatorAsync` | boolean | <optional> | When true (not truthy) the validator is treated asynchornously and returns a promise with your value.

  Source:
    - documents/binder.js, line 92

  ##### Returns:

  Type
    *

#### <static> unbind(path, record)

  You can unbind previously bound objects from here.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `path` | string | The path that was bound using module:documents/binder.bind
  `record` | * | The object that was bound

  Source:
    - documents/binder.js, line 36