@danielkalen/simplybind
Version:
Magically simple, framework-less one-way/two-way data binding for frontend/backend in ~5kb.
24 lines (16 loc) • 923 B
text/coffeescript
SimplyBind = (subject, options, saveOptions, isSub, completeCallback)->
if (!subject and subject isnt 0) or (!checkIf.isString(subject) and !checkIf.isNumber(subject) and !checkIf.isFunction(subject) and subject not instanceof Array)
throwError('invalidParamName') unless checkIf.isBindingInterface(subject)
if checkIf.isObject(subject) and subject not instanceof Array # Indicates it's a Binding instance object due to the above check
interfaceToReturn = if completeCallback then completeCallback(subject) else subject.selfClone()
else
newInterface = new BindingInterface(options)
newInterface.saveOptions = saveOptions
newInterface.isSub = isSub
newInterface.completeCallback = completeCallback
if checkIf.isFunction(subject)
interfaceToReturn = newInterface.setObject(subject, true)
else
interfaceToReturn = newInterface.setProperty(subject)
return interfaceToReturn
import './methods'