lookout

Subscribe to object property changes.


Keywords
change, changes, notification, notifications, watch
License
MIT
Install
bower install lookout

Documentation

Lookout Build Status

Create subscriptions for object property changes.

Getting Started

Download the production version or the development version or install using bower: bower install lookout.

In your web page:

var something = { name: 'something' };

// Watch the object's properties using lookout.
lookout(something, function() {
  console.log('Something just changed');
});

// Unwatch the object's properties using disregard.
disregard(something);

Browser support

Lookout does not support Internet Explorer 6 or 7. All other browsers and versions are supported.

Examples

Lookout allows you to subscribe to change notifications on an object for things like validation and ensures that this is the object that changed:

var myObject = { id: 100, name: 'my object' };

lookout(myObject, 'name', function() {
  // this is the object that just changed.
  if (this.name.length === 0) {
    alert('Invalid name value!');
  }
});

The notification callback also passes the name of the property that changed, the old value, and the new value:

var myObject = { id: 100, name: 'my object' };

lookout(myObject, function(prop, oldValue, newValue) {
  console.log(prop + ' just changed from [' + oldValue + '] to [' + newValue + ']');
});

Release History

  • 2013/10/18 - v0.1.2 - Major rework of the build system and corrected disregard functionality.
  • 2012/11/27 - v0.1.1 - Bug fixes.
  • 2012/11/15 - v0.1.0 - Initial release.

License

Copyright (c) 2014 Matt Hernandez

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.