Last active
July 28, 2018 14:18
-
-
Save ianaya89/f9a176e27ff394ca0b6af5f2ca6d838a to your computer and use it in GitHub Desktop.
BiuSheiEs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function r(obj, cb) { | |
const wrapped = {} | |
for (let k in obj) { | |
let value = obj[k] | |
if (typeof value === 'object' && !Array.isArray(value)) { | |
value = r(value, cb) | |
} | |
Object.defineProperty(wrapped, k, { | |
get () { | |
return value | |
}, | |
set (newValue) { | |
console.log('New value: ', newValue) | |
value = newValue | |
cb() | |
} | |
}) | |
} | |
return wrapped | |
} | |
function BiuSheiEs (vm) { | |
const data = vm.data || {} | |
const render = vm.render.bind(vm) | |
vm.data = r(data, render) | |
return vm | |
} | |
const component = new BiuSheiEs({ | |
el: document.getElementById('app'), | |
data: { | |
user: { | |
name: '@ianaya89' | |
} | |
}, | |
render () { | |
this.el.innerHTML = `<h1>Welcome ${this.data.user.name}</h1>` | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment