Skip to content

Commit 5fa5f49

Browse files
committed
Initial commit
0 parents  commit 5fa5f49

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea/
2+
node_modules/

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Inbound.js
2+
3+
Inbound.js provides modern javascript data binding and view synchronization by employing native `Object` getters and setters combined with `MutationObserver`.
4+
5+
## Benefits of Inbound.js
6+
7+
- Not a framework
8+
- Native, real-time data binding (no dirty checking)
9+
- Makes no assumptions about your application architecture
10+
- No other library dependencies
11+
- ES5 compatible down to IE9 (without `MutationObserver` features)
12+
- Encourages a MAD (modular application development) pattern
13+
- Discourages a FAD (framework application development) pattern

package.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "inboundjs",
3+
"version": "0.1.0",
4+
"description": "Modern javascript data binding and view synchronization.",
5+
"main": "src/inbound.js",
6+
"scripts": {
7+
"test": "npm test"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/pklauzinski/inbound.git"
12+
},
13+
"keywords": [
14+
"data-binding",
15+
"getters",
16+
"setters",
17+
"mutationobserver",
18+
"real-time"
19+
],
20+
"author": "Philip Klauzinski",
21+
"license": "MIT",
22+
"bugs": {
23+
"url": "https://github.com/pklauzinski/inbound/issues"
24+
},
25+
"homepage": "https://github.com/pklauzinski/inbound#readme",
26+
"devDependencies": {
27+
"rollup": "^0.33.0"
28+
}
29+
}

src/inbound.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
var inbound = function(obj, prop) {
2+
var input = document.querySelector('[name="' + prop + '"]');
3+
var observer = new MutationObserver(function(mutations) {
4+
mutations.forEach(function(mutation) {
5+
var val = mutation.target.innerHTML;
6+
if (obj[prop] !== val) {
7+
console.log('Inequality detected: "' + obj[prop] + '" !== "' + val + '"');
8+
obj[prop] = mutation.target.innerHTML;
9+
}
10+
});
11+
});
12+
var config = {
13+
attributes: true,
14+
childList: true,
15+
characterData: true
16+
};
17+
var list = document.querySelectorAll('[data-bind="' + prop + '"]'), i;
18+
for (i = 0; i < list.length; i++) {
19+
observer.observe(list[i], config);
20+
}
21+
input.value = obj[prop] || input.value;
22+
Object.defineProperty(obj, prop, {
23+
get: function() {
24+
return input.value;
25+
},
26+
set: function(val) {
27+
var list = document.querySelectorAll('[data-bind="' + prop + '"]'), i;
28+
for (i = 0; i < list.length; i++) {
29+
list[i].innerHTML = val;
30+
}
31+
input.value = val;
32+
},
33+
configurable: true,
34+
enumerable: true
35+
});
36+
obj[prop] = obj[prop];
37+
input.oninput = function() {
38+
obj[prop] = obj[prop];
39+
};
40+
};

0 commit comments

Comments
 (0)