UNPKG

@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
GroupBinding = (bindingInterface, objects, objectType)-> extendState(@, @interface = bindingInterface) @isMulti = true @bindings = bindings = [] if objects @addBinding(object, objectType) 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 @bindings b = binding if methodName is 'updateSub' binding[methodName](a,b,c,d) return proto.addBinding = (object, objectType)-> @bindings.push if not objectType then object else @createBinding(object, objectType, @interface) return