Skip to content

dcporter/mvcobject.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Available on GitHub.

Super Lightweight JS Binding & KVO

When even Angular is overkill, drop in MVCObject.js for fast, easy, lightweight binding and KVO.

This object implements the Google Maps API's very useful MVCObject interface, documented here. This project is forked from this excellent but apparently abandoned one; John and Mark deserve the credit. This version tones down the object's tendency to throw errors, making it much friendlier to use.

Example

Binding:

var objectA = new MVCObject(),
	objectB = new MVCObject();

// Always use setters and getters.
objectA.set('name', 'John');
objectB.set('name', 'Mark');

// Set up a binding - one line. This syncs the values, overrides the value on objectB.
objectB.bindTo('name', objectA);

objectB.get('name');
// > 'John'

objectA.set('name', 'Dave');
objectB.get('name');
// > 'Dave'

Key-Value Observing:

var objectA = new MVCObject();
objectA.set('name', 'John');

objectA.name_changed = function() { console.log("Name changed to: " + this.get('name')); };

objectA.set('name', 'Dave');
// > "Name changed to: Dave"

Subclassing (obvious but very handy):

ObjectA = function() {};
ObjectA.prototype = new MVCObject();
ObjectA.prototype.constructor = ObjectA;

License

Like its predecessor, this is available under the Apache License 2.0 (see included LICENSE).

About

Super-lightweight JavaScript KVO.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published