@danielkalen/simplybind
Version:
Magically simple, framework-less one-way/two-way data binding for frontend/backend in ~5kb.
41 lines (28 loc) • 1.19 kB
text/coffeescript
suite ".transformAll()", ()->
suiteSetup(restartSandbox)
test "Behaves the same way as .transform() does, except it applies the transform to all of the declared subscribers", ()->
dispatcher = 'value': 'current'
objectA.prop = objectC.prop = objectC.prop = ''
SimplyBind('value').of(dispatcher)
.to('prop').of(objectA)
.and.to('prop').of(objectB)
.and.to('prop').of(objectC)
.transformAll (newValue, currentValue)-> newValue+'+'+currentValue
for value in [objectA.prop, objectB.prop, objectC.prop]
expect(value).to.equal 'current+current'
dispatcher.value = 'new'
for value in [objectA.prop, objectB.prop, objectC.prop]
expect(value).to.equal 'new+current+current'
dispatcher.value = 'newer'
for value in [objectA.prop, objectB.prop, objectC.prop]
expect(value).to.equal 'newer+new+current+current'
restartSandbox()
test "Will allow additional binding subscribers after being called", ()->
expect(()->
SimplyBind('prop1').of(objectA)
.to('prop1').of(objectB)
.and.to('prop2').of(objectB)
.and.to('prop3').of(objectB)
.transformAll (value)-> value
.and.to('prop4').of(objectB)
).not.to.throw()