@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
text/coffeescript
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: ()-> [.length-1]
createBinding: (subject, newObjectType, isSimpleObject, isProxiedFunc, bindingInterface)->
= subject
cachedBinding = cache.get(subject, isSimpleObject, , )
if cachedBinding # Exit early by returning the subject from cache if is already in there
return
else
newBinding = new Binding(subject, newObjectType, bindingInterface or @, isProxiedFunc)
cache.set(newBinding, isSimpleObject)
return newBinding
patchCachedBinding: (cachedBinding)->
cachedBinding.placeholder =
if 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 not of # This property was manually deleted and needs its prop to be re-defined as a live one
cachedBinding.makePropertyLive(true)
setOptionsForBinding(cachedBinding, )
return cachedBinding
BindingInterface:: = Object.create(BindingInterfacePrivate)