Skip to content
Two way binding concept between Objects and DOM elements using MutationObserver.
JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
dist Adds karma to grunt.
lib Initial commit.
src
tests
.gitignore
Gruntfile.js Adds karma to grunt.
README.md
bower.json Removes trailing comma.
karma.conf.js
package.json

README.md

BoundObject.js

Two way binding of Object properties and DOM nodes. BoundObject.someProperty changes? So does the associated nodes textContent. A target node's textContent changes? So does the associated Object property.

Currently only supports textContent changes on the node. Attributues should be possible. As well as working with templates.

Example

var target = document.querySelector('#fun');
var myModel = new BoundObject({
  'fun': target
});

// Will set bound node's textContent as well
myModel.set('fun', 'Hello');


// Will set node's textContent on bound property
target.textContent = 'World!';

// stick other properties
var testTarget = document.querySelector('#test');
myModel.test = 'neato';

// value of `myModel.test` will be pushed to `testTarget` node
myModel.stick('test', testTarget);

To get a better idea of how it works, read through tests/boundobject.spec.js. Run the test with npm test.

Why?

At Ecquire we use MutationObserver's in place of setInterval to check when/where we should inject our HTML.

It's a cool API and seemed like an appropriate solution to binding JavaScript Object properties to DOM nodes.

Note

This has not been used in any production code and is more of a concept at this point. Ideas and contributions are more than welcome.

Something went wrong with that request. Please try again.