UNPKG

@danielkalen/simplybind

Version:

Magically simple, framework-less one-way/two-way data binding for frontend/backend in ~5kb.

43 lines (33 loc) 1.26 kB
suite ".chainTo()/.pipe()", ()-> suiteSetup(restartSandbox) test "Helps create complex chainings", ()-> outerstate = 'first': null 'second': null 'third': null objectA.prop1 = 'Hello World' SimplyBind('prop1').of(objectA) .to('prop1').of(objectB) .and.to('prop2').of(objectA) .and.to (val)-> outerstate.first = val .transformAll (val)-> val.toUpperCase() .chainTo('prop2').of(objectB) .and.to('prop3').of(objectA) .transform (val)-> val.toLowerCase() .chainTo('prop3').of(objectB) .and.to('prop4').of(objectA) .and.to (val)-> outerstate.second = val .chainTo('prop4').of(objectB) .and.to (val)-> outerstate.third = val.slice(0, 5) expect(outerstate.first).to.equal 'HELLO WORLD' expect(outerstate.second).to.equal 'hello world' expect(outerstate.third).to.equal 'hello' expect(objectA.prop1).to.equal 'Hello World' expect(objectA.prop2).to.equal 'HELLO WORLD' expect(objectB.prop1).to.equal 'HELLO WORLD' expect(objectB.prop2).to.equal 'HELLO WORLD' expect(objectA.prop3).to.equal 'hello world' expect(objectB.prop3).to.equal 'hello world' expect(objectA.prop4).to.equal 'hello world' expect(objectB.prop4).to.equal 'hello world' restartSandbox()