UNPKG

@danielkalen/simplybind

Version:

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

64 lines (48 loc) 2.08 kB
suite ".setOption()", ()-> test "should update the specified option only for the target interface and not modify global default options", ()-> SimplyBind.defaultOptions.updateOnBind = false expect(SimplyBind.defaultOptions.updateOnBind).to.be.false pubInterface = SimplyBind('prop1').of(objectA) subInterface = SimplyBind('prop1').of(objectB) binding = pubInterface.to(subInterface) metaData = pubInterface._.subsMeta or pubInterface._.sM opts = metaData[subInterface._.ID].opts expect(opts.updateOnBind).to.be.false binding.setOption 'updateOnBind', true expect(opts.updateOnBind).to.be.true expect(SimplyBind.defaultOptions.updateOnBind).to.be.false SimplyBind.defaultOptions.updateOnBind = true restartSandbox() test "should only update the options for the last added sub in a chain", ()-> SimplyBind.defaultOptions.updateEvenIfSame = false SimplyBind.defaultOptions.updateOnBind = false dispatcher = 'prop':'value' receivers = {1,2,3,4} updateCount = 1:0, 2:0, 3:0, 4:0 bindings = 1: SimplyBind(1).of(receivers).to ()-> updateCount[1]++ 2: SimplyBind(2).of(receivers).to ()-> updateCount[2]++ 3: SimplyBind(3).of(receivers).to ()-> updateCount[3]++ 4: SimplyBind(4).of(receivers).to ()-> updateCount[4]++ expect(updateCount[1]).to.equal 0 expect(updateCount[2]).to.equal 0 expect(updateCount[3]).to.equal 0 expect(updateCount[4]).to.equal 0 SimplyBind('prop').of(dispatcher) .to(1).of(receivers) .and.to(2).of(receivers) .and.to(3).of(receivers).setOption('updateEvenIfSame', true) .and.to(4).of(receivers) bindings[3].setOption('updateEvenIfSame', true) dispatcher.prop = 'anotherValue' expect(updateCount[1]).to.equal 1 expect(updateCount[2]).to.equal 1 expect(updateCount[3]).to.equal 1 expect(updateCount[4]).to.equal 1 dispatcher.prop = dispatcher.prop expect(updateCount[1]).to.equal 1 expect(updateCount[2]).to.equal 1 expect(updateCount[3]).to.equal 2 expect(updateCount[4]).to.equal 1 SimplyBind.defaultOptions.updateOnBind = true restartSandbox()