Skip to content

Instantly share code, notes, and snippets.

@debugmodedotnet
Created August 27, 2019 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save debugmodedotnet/71763b530f5aec800179ddff892cf58d to your computer and use it in GitHub Desktop.
Save debugmodedotnet/71763b530f5aec800179ddff892cf58d to your computer and use it in GitHub Desktop.
var elements = document.querySelectorAll('[data-geek97-bind]');
var dbrepo = {};
elements.forEach((element) => {
if (element.type === 'text') {
var bindingProperty = element.getAttribute('data-geek97-bind');
addToScope();
element.onkeyup = () => {
dbrepo[bindingProperty] = element.value;
}
}
function addToScope() {
if (!dbrepo.hasOwnProperty(bindingProperty)) {
let value;
Object.defineProperty(dbrepo, bindingProperty, {
configurable: true,
enumerable: true,
set: function (newvalue) {
value = newvalue;
elements.forEach(e => {
if (e.getAttribute('data-geek97-bind') === bindingProperty) {
if (e.type === 'text') {
e.value = newvalue
}
else if (!e.type) {
e.innerHTML = newvalue
}
}
})
},
get: function () {
return value;
}
})
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment