@danielkalen/simplybind
Version:
Magically simple, framework-less one-way/two-way data binding for frontend/backend in ~5kb.
32 lines (20 loc) • 1.04 kB
text/coffeescript
GroupBinding = (bindingInterface, objects, objectType)->
extendState(@, = bindingInterface)
= true
= bindings = []
if objects
for object in objects
Object.defineProperties @,
'type': get: ()-> bindings.map (binding)-> binding.type
'value': get: ()-> bindings.map (binding)-> if binding.placeholder then binding.pholderValues[binding.placeholder] else binding.value
'throttleRate': set: (newRate)-> bindings.forEach (binding)-> binding.throttleRate = newRate
proto = GroupBinding:: = Object.create(BindingInterfacePrivate)
Object.keys(Binding::).forEach (methodName)->
proto[methodName] = (a,b,c,d)-> # Four arguments is the most ever passed to any method from BindingInterface methods
for binding in
b = binding if methodName is 'updateSub'
binding[methodName](a,b,c,d)
return
proto.addBinding = (object, objectType)->
.push if not objectType then object else
return