smart-observe demo: watch

by longhao he

HTML

<script src="https://unpkg.com/smart-observe/dist/smart-observe.min.js"></script>

Babel + JSX

/* https://github.com/cnlon/smart-observe */

const target = {a: 1}
observe(target, 'a', function (newValue, oldValue) {
  print(newValue, oldValue)
})
target.a = 3
// 3 1


function print(...args) {
  const content = args.join(' ') + '<br>'
  document.body.innerHTML += content
}