UNPKG

@danielkalen/simplybind

Version:

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

32 lines (20 loc) 958 B
GroupBinding = (bindingInterface, objects, objectType)-> bindingInterface.selector = bindingInterface.selector.slice(6) # Take out the 'multi:' 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)-> binding.value 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