UNPKG

@danielkalen/simplybind

Version:

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

47 lines (29 loc) 1.57 kB
BindingInterfacePrivate = new: (stage, object)-> new BindingInterface(@_, stage, @, object) defineMainProps: (binding)-> @_ = binding Object.defineProperties @, 'ID': get: ()-> binding.ID 'value': get: ()-> binding.value 'original': get: ()-> binding.objects or binding.object 'dependents': get: ()-> binding.deps.slice().map (dep)-> dep.object 'lastProxied': get: ()-> @proxies[@proxies.length-1] createBinding: (subject, newObjectType, isSimpleObject, isProxiedFunc, bindingInterface)-> @object = subject cachedBinding = cache.get(subject, isSimpleObject, @selector, @isMultiChoice) if cachedBinding # Exit early by returning the subject from cache if is already in there return @patchCachedBinding(cachedBinding) else newBinding = new Binding(subject, newObjectType, bindingInterface or @, isProxiedFunc) cache.set(newBinding, isSimpleObject) return newBinding patchCachedBinding: (cachedBinding)-> cachedBinding.placeholder = @placeholder if @placeholder and not cachedBinding.pholderValues # A cached version with no placeholders set exists - needs scanning cachedBinding.valueOriginal = cachedBinding.fetchDirectValue() cachedBinding.scanForPholders() if cachedBinding.type is 'ObjectProp' and @property not of @object # This property was manually deleted and needs its prop to be re-defined as a live one cachedBinding.makePropertyLive(true) setOptionsForBinding(cachedBinding, @optionsPassed) return cachedBinding BindingInterface:: = Object.create(BindingInterfacePrivate)