UNPKG

@danielkalen/simplybind

Version:

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

313 lines (284 loc) 15.7 kB
suite "Method availablity in different stages", ()-> test "Stage 0 (Selection Stage)", ()-> binding = ()-> SimplyBind('1') expect(()-> binding().once.to).to.throw() expect(()-> binding().of objectA).not.to.throw() expect(()-> binding().to 'prop2').to.throw() expect(()-> binding().and.to 'prop2').to.throw() expect(()-> binding().set 'value').to.throw() expect(()-> binding().transform ()->).to.throw() expect(()-> binding().transformAll ()->).to.throw() expect(()-> binding().transformSelf ()->).to.throw() expect(()-> binding().condition ()->).to.throw() expect(()-> binding().conditionAll ()->).to.throw() expect(()-> binding().bothWays()).to.throw() expect(()-> binding().setOption('v', 'a')).to.throw() expect(()-> binding().stopPolling()).to.throw() expect(()-> binding().pollEvery(1000).stopPolling()).to.throw() expect(()-> binding().unBind()).to.throw() expect(()-> binding().chainTo ()->).to.throw() expect(()-> binding().updateOn 'a').to.throw() expect(()-> binding().removeUpdater 'a').to.throw() expect(()-> binding().updateOn('a').of({}).removeUpdater 'a').to.throw() binding = ()-> SimplyBind('event:click') expect(()-> binding().once.to).to.throw() expect(()-> binding().of objectA).not.to.throw() expect(()-> binding().to 'prop2').to.throw() expect(()-> binding().and.to 'prop2').to.throw() expect(()-> binding().set 'value').to.throw() expect(()-> binding().transform ()->).to.throw() expect(()-> binding().transformAll ()->).to.throw() expect(()-> binding().transformSelf ()->).to.throw() expect(()-> binding().condition ()->).to.throw() expect(()-> binding().conditionAll ()->).to.throw() expect(()-> binding().bothWays()).to.throw() expect(()-> binding().setOption('v', 'a')).to.throw() expect(()-> binding().stopPolling()).to.throw() expect(()-> binding().pollEvery(1000).stopPolling()).to.throw() expect(()-> binding().unBind()).to.throw() expect(()-> binding().chainTo ()->).to.throw() expect(()-> binding().updateOn 'a').to.throw() expect(()-> binding().removeUpdater 'a').to.throw() expect(()-> binding().updateOn('a').of({}).removeUpdater 'a').to.throw() binding = ()-> SimplyBind('1').of(objectA).to 'prop1' expect(()-> binding().once.to).to.throw() expect(()-> binding().of objectA).not.to.throw() expect(()-> binding().to 'prop2').to.throw() expect(()-> binding().and.to 'prop2').to.throw() expect(()-> binding().set 'value').to.throw() expect(()-> binding().transform ()->).to.throw() expect(()-> binding().transformAll ()->).to.throw() expect(()-> binding().transformSelf ()->).to.throw() expect(()-> binding().condition ()->).to.throw() expect(()-> binding().conditionAll ()->).to.throw() expect(()-> binding().bothWays()).to.throw() expect(()-> binding().setOption('v', 'a')).to.throw() expect(()-> binding().stopPolling()).to.throw() expect(()-> binding().pollEvery(1000).stopPolling()).to.throw() expect(()-> binding().unBind()).to.throw() expect(()-> binding().chainTo ()->).to.throw() expect(()-> binding().updateOn 'a').to.throw() expect(()-> binding().removeUpdater 'a').to.throw() expect(()-> binding().updateOn('a').of({}).removeUpdater 'a').to.throw() binding = ()-> SimplyBind('1').of(objectA).to('prop:prop1').of(objectB).and.to 'prop2' expect(()-> binding().once.to).to.throw() expect(()-> binding().of objectA).not.to.throw() expect(()-> binding().to 'prop2').to.throw() expect(()-> binding().and.to 'prop2').to.throw() expect(()-> binding().set 'value').to.throw() expect(()-> binding().transform ()->).to.throw() expect(()-> binding().transformAll ()->).to.throw() expect(()-> binding().transformSelf ()->).to.throw() expect(()-> binding().condition ()->).to.throw() expect(()-> binding().conditionAll ()->).to.throw() expect(()-> binding().bothWays()).to.throw() expect(()-> binding().setOption('v', 'a')).to.throw() expect(()-> binding().stopPolling()).to.throw() expect(()-> binding().pollEvery(1000).stopPolling()).to.throw() expect(()-> binding().unBind()).to.throw() expect(()-> binding().chainTo ()->).to.throw() expect(()-> binding().updateOn 'a').to.throw() expect(()-> binding().removeUpdater 'a').to.throw() expect(()-> binding().updateOn('a').of({}).removeUpdater 'a').to.throw() test "Stage 1 (Indication Stage)", ()-> binding = ()-> SimplyBind('1').of objectA expect(()-> binding().once.to).not.to.throw() expect(()-> binding().of objectA).to.throw() expect(()-> binding().to 'prop2').not.to.throw() expect(()-> binding().and.to 'prop2').to.throw() expect(()-> binding().set 'value').not.to.throw() expect(()-> binding().transform ()->).to.throw() expect(()-> binding().transformAll ()->).to.throw() expect(()-> binding().transformSelf ()->).not.to.throw() expect(()-> binding().condition ()->).to.throw() expect(()-> binding().conditionAll ()->).to.throw() expect(()-> binding().bothWays()).to.throw() expect(()-> binding().setOption('v', 'a')).to.throw() expect(()-> binding().stopPolling()).not.to.throw() expect(()-> binding().pollEvery(1000).stopPolling()).not.to.throw() expect(()-> binding().unBind()).to.throw() expect(()-> binding().chainTo ()->).to.throw() expect(()-> binding().updateOn 'a').not.to.throw() expect(()-> binding().removeUpdater 'a').to.throw() expect(()-> binding().updateOn('a').of({}).removeUpdater 'a').not.to.throw() test "Stage 2 (Binding Complete Stage)", ()-> binding = ()-> SimplyBind('1').of(objectA).to('prop1').of objectB expect(()-> binding().once.to).to.throw() expect(()-> binding().of objectA).to.throw() expect(()-> binding().to 'prop2').to.throw() expect(()-> binding().and.to 'prop2').not.to.throw() expect(()-> binding().set 'value').not.to.throw() expect(()-> binding().transform ()->).not.to.throw() expect(()-> binding().transformAll ()->).not.to.throw() expect(()-> binding().transformSelf ()->).to.throw() expect(()-> binding().condition ()->).not.to.throw() expect(()-> binding().conditionAll ()->).not.to.throw() expect(()-> binding().bothWays()).not.to.throw() expect(()-> binding().setOption('v', 'a')).not.to.throw() expect(()-> binding().stopPolling()).not.to.throw() expect(()-> binding().pollEvery(1000).stopPolling()).not.to.throw() expect(()-> binding().unBind()).not.to.throw() expect(()-> binding().chainTo ()->).not.to.throw() expect(()-> binding().updateOn 'a').not.to.throw() expect(()-> binding().updateOn('a').of(window).removeUpdater 'a').not.to.throw() binding = ()-> SimplyBind('1').of(objectA).to('prop1').of(objectB).and.to('prop2').of objectB expect(()-> binding().once.to).to.throw() expect(()-> binding().of objectA).to.throw() expect(()-> binding().to 'prop2').to.throw() expect(()-> binding().and.to 'prop2').not.to.throw() expect(()-> binding().set 'value').not.to.throw() expect(()-> binding().transform ()->).not.to.throw() expect(()-> binding().transformAll ()->).not.to.throw() expect(()-> binding().transformSelf ()->).to.throw() expect(()-> binding().condition ()->).not.to.throw() expect(()-> binding().conditionAll ()->).not.to.throw() expect(()-> binding().bothWays()).not.to.throw() expect(()-> binding().setOption('v', 'a')).not.to.throw() expect(()-> binding().stopPolling()).not.to.throw() expect(()-> binding().pollEvery(1000).stopPolling()).not.to.throw() expect(()-> binding().unBind()).not.to.throw() expect(()-> binding().chainTo ()->).not.to.throw() expect(()-> binding().updateOn 'a').not.to.throw() expect(()-> binding().updateOn('a').of(window).removeUpdater 'a').not.to.throw() binding = ()-> SimplyBind('1').of(objectA).to('prop1').of(objectB).bothWays() expect(()-> binding().once.to).to.throw() expect(()-> binding().of objectA).to.throw() expect(()-> binding().to 'prop2').to.throw() expect(()-> binding().and.to 'prop2').not.to.throw() expect(()-> binding().set 'value').not.to.throw() expect(()-> binding().transform ()->).not.to.throw() expect(()-> binding().transformAll ()->).not.to.throw() expect(()-> binding().transformSelf ()->).to.throw() expect(()-> binding().condition ()->).not.to.throw() expect(()-> binding().conditionAll ()->).not.to.throw() expect(()-> binding().bothWays()).not.to.throw() expect(()-> binding().setOption('v', 'a')).not.to.throw() expect(()-> binding().stopPolling()).not.to.throw() expect(()-> binding().pollEvery(1000).stopPolling()).not.to.throw() expect(()-> binding().unBind()).not.to.throw() expect(()-> binding().chainTo ()->).not.to.throw() expect(()-> binding().updateOn 'a').not.to.throw() expect(()-> binding().updateOn('a').of(window).removeUpdater 'a').not.to.throw() binding = ()-> SimplyBind('1').of(objectA).to('prop1').of(objectB).transform ()-> expect(()-> binding().once.to).to.throw() expect(()-> binding().of objectA).to.throw() expect(()-> binding().to 'prop2').to.throw() expect(()-> binding().and.to 'prop2').not.to.throw() expect(()-> binding().set 'value').not.to.throw() expect(()-> binding().transform ()->).not.to.throw() expect(()-> binding().transformAll ()->).not.to.throw() expect(()-> binding().transformSelf ()->).to.throw() expect(()-> binding().condition ()->).not.to.throw() expect(()-> binding().conditionAll ()->).not.to.throw() expect(()-> binding().bothWays()).not.to.throw() expect(()-> binding().setOption('v', 'a')).not.to.throw() expect(()-> binding().stopPolling()).not.to.throw() expect(()-> binding().pollEvery(1000).stopPolling()).not.to.throw() expect(()-> binding().unBind()).not.to.throw() expect(()-> binding().chainTo ()->).not.to.throw() expect(()-> binding().updateOn 'a').not.to.throw() expect(()-> binding().updateOn('a').of(window).removeUpdater 'a').not.to.throw() binding = ()-> SimplyBind('1').of(objectA).to('prop1').of(objectB).transformAll ()-> expect(()-> binding().once.to).to.throw() expect(()-> binding().of objectA).to.throw() expect(()-> binding().to 'prop2').to.throw() expect(()-> binding().and.to 'prop2').not.to.throw() expect(()-> binding().set 'value').not.to.throw() expect(()-> binding().transform ()->).not.to.throw() expect(()-> binding().transformAll ()->).not.to.throw() expect(()-> binding().transformSelf ()->).to.throw() expect(()-> binding().condition ()->).not.to.throw() expect(()-> binding().conditionAll ()->).not.to.throw() expect(()-> binding().bothWays()).not.to.throw() expect(()-> binding().setOption('v', 'a')).not.to.throw() expect(()-> binding().stopPolling()).not.to.throw() expect(()-> binding().pollEvery(1000).stopPolling()).not.to.throw() expect(()-> binding().unBind()).not.to.throw() expect(()-> binding().chainTo ()->).not.to.throw() expect(()-> binding().updateOn 'a').not.to.throw() expect(()-> binding().updateOn('a').of(window).removeUpdater 'a').not.to.throw() binding = ()-> SimplyBind('1').of(objectA).to('prop1').of(objectB).condition ()-> expect(()-> binding().once.to).to.throw() expect(()-> binding().of objectA).to.throw() expect(()-> binding().to 'prop2').to.throw() expect(()-> binding().and.to 'prop2').not.to.throw() expect(()-> binding().set 'value').not.to.throw() expect(()-> binding().transform ()->).not.to.throw() expect(()-> binding().transformAll ()->).not.to.throw() expect(()-> binding().transformSelf ()->).to.throw() expect(()-> binding().condition ()->).not.to.throw() expect(()-> binding().conditionAll ()->).not.to.throw() expect(()-> binding().bothWays()).not.to.throw() expect(()-> binding().setOption('v', 'a')).not.to.throw() expect(()-> binding().stopPolling()).not.to.throw() expect(()-> binding().pollEvery(1000).stopPolling()).not.to.throw() expect(()-> binding().unBind()).not.to.throw() expect(()-> binding().chainTo ()->).not.to.throw() expect(()-> binding().updateOn 'a').not.to.throw() expect(()-> binding().updateOn('a').of(window).removeUpdater 'a').not.to.throw() binding = ()-> SimplyBind('1').of(objectA).to('prop1').of(objectB).conditionAll ()-> expect(()-> binding().once.to).to.throw() expect(()-> binding().of objectA).to.throw() expect(()-> binding().to 'prop2').to.throw() expect(()-> binding().and.to 'prop2').not.to.throw() expect(()-> binding().set 'value').not.to.throw() expect(()-> binding().transform ()->).not.to.throw() expect(()-> binding().transformAll ()->).not.to.throw() expect(()-> binding().transformSelf ()->).to.throw() expect(()-> binding().condition ()->).not.to.throw() expect(()-> binding().conditionAll ()->).not.to.throw() expect(()-> binding().bothWays()).not.to.throw() expect(()-> binding().setOption('v', 'a')).not.to.throw() expect(()-> binding().stopPolling()).not.to.throw() expect(()-> binding().pollEvery(1000).stopPolling()).not.to.throw() expect(()-> binding().unBind()).not.to.throw() expect(()-> binding().chainTo ()->).not.to.throw() expect(()-> binding().updateOn 'a').not.to.throw() expect(()-> binding().updateOn('a').of(window).removeUpdater 'a').not.to.throw() binding = ()-> SimplyBind('1').of(objectA).to('prop1').of(objectB).transform(()->).and.to ()-> expect(()-> binding().once.to).to.throw() expect(()-> binding().of objectA).to.throw() expect(()-> binding().to 'prop2').to.throw() expect(()-> binding().and.to 'prop2').not.to.throw() expect(()-> binding().set 'value').not.to.throw() expect(()-> binding().transform ()->).not.to.throw() expect(()-> binding().transformAll ()->).not.to.throw() expect(()-> binding().transformSelf ()->).to.throw() expect(()-> binding().condition ()->).not.to.throw() expect(()-> binding().conditionAll ()->).not.to.throw() expect(()-> binding().bothWays()).not.to.throw() expect(()-> binding().setOption('v', 'a')).not.to.throw() expect(()-> binding().stopPolling()).not.to.throw() expect(()-> binding().pollEvery(1000).stopPolling()).not.to.throw() expect(()-> binding().unBind()).not.to.throw() expect(()-> binding().chainTo ()->).not.to.throw() expect(()-> binding().updateOn 'a').not.to.throw() expect(()-> binding().updateOn('a').of(window).removeUpdater 'a').not.to.throw() binding = ()-> SimplyBind('1').of(objectA).to('prop1').of(objectB).transform(()->).and.to(()->).chainTo ()-> expect(()-> binding().once.to).to.throw() expect(()-> binding().of objectA).to.throw() expect(()-> binding().to 'prop2').to.throw() expect(()-> binding().and.to 'prop2').not.to.throw() expect(()-> binding().set 'value').not.to.throw() expect(()-> binding().transform ()->).not.to.throw() expect(()-> binding().transformAll ()->).not.to.throw() expect(()-> binding().transformSelf ()->).to.throw() expect(()-> binding().condition ()->).not.to.throw() expect(()-> binding().conditionAll ()->).not.to.throw() expect(()-> binding().bothWays()).not.to.throw() expect(()-> binding().setOption('v', 'a')).not.to.throw() expect(()-> binding().stopPolling()).not.to.throw() expect(()-> binding().pollEvery(1000).stopPolling()).not.to.throw() expect(()-> binding().unBind()).not.to.throw() expect(()-> binding().chainTo ()->).not.to.throw() expect(()-> binding().updateOn 'a').not.to.throw() expect(()-> binding().updateOn('a').of(window).removeUpdater 'a').not.to.throw() test "Aliases", ()-> binding = SimplyBind('prop').of(objectA).to('prop').of(objectB) expect(binding.update).to.equal(binding.set) expect(binding.twoWay).to.equal(binding.bothWays) expect(binding.pipe).to.equal(binding.chainTo) expect(()-> binding.set('value')).not.to.throw() expect(()-> binding.twoWay()).not.to.throw() expect(()-> binding.pipe('a')).not.to.throw() restartSandbox()