return this.use('[data-watch]', function(el, data) { var path = el.attributes['data-watch'].value data.watch = watch(this, path, function(current, previous) { if (data.exec) data.exec(el, data, current, previous) }) return data })
it('can take a custom poll interval', function(done) { var count = 0 var start = Date.now() var slowWatch = Watch(100) slowWatch(user, 'queriedAgo()', function(property) { if (count++ == 0) return start = Date.now() // skip first call if (Date.now() - start < slowWatch.interval) throw new Error('polled too quickly: ' + (Date.now() - start) + ' < ' + slowWatch.interval) start = Date.now() if (count++ > 5) done() }) })
it('can unwatch custom check intervals', function(done) { var called = false user.doError = function() { // will call once. if (!called) return called = true throw new Error('should not fire') } var slowWatch = Watch(100) slowWatch(user, 'doError()', function(property) { throw new Error('callback should not fire') }) slowWatch.unwatch(user, 'doError()') setTimeout(function() { done() }, slowWatch.interval * 2) })
"use strict" if (typeof window === "undefined") { var Watch = require('../') var assert = require('assert') } else { var Watch = require('simple-watch') var assert = require('timoxley-assert') } var watch = Watch() var user beforeEach(function() { user = { name: 'Tim', age: 27 } }) afterEach(function() { watch.unwatch() }) var shouldNotCall = function() { throw new Error('Should not fire') } describe('error conditions', function() { it('throws when given no arguments', function() { assert.throws(function() {