UNPKG

@danielkalen/simplybind

Version:

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

50 lines (38 loc) 1.5 kB
###* * Stage definitions: * * 0: Selection: Got selector, awaiting object. * 1: Indication: Got object, awaiting proxied property / function / Binding-object. * 2: Binding Complete: Complete, awaiting additional (optional) bindings/mutations. ### BindingInterface = (inheritedState, stage, subject, options, parentInterface, isSibling, saveOptions)-> extendState(@, inheritedState) if inheritedState @stage = stage or 0 @subs ?= [] @saveOptions = saveOptions if saveOptions @isSibling = isSibling if isSibling @parentInterface = parentInterface if parentInterface if @stage is 0 @optionsPassed = options ||= {} @options = {} for key of defaultOptions @options[key] = if options[key]? then options[key] else defaultOptions[key] if checkIf.isSimpleObject(subject) @stage = 1 return @setObject(subject, true) else subject = subject.toString() if checkIf.isNumber(subject) @selector = @property = subject unless @options.simpleSelector if targetIncludes(@selector, ':') split = @property.split(':') @descriptor = split[0] # An addl. string in the selector name defining the scope of the selection (i.e. SimplyBind('attr:class')) @property = split[1] if targetIncludes(@selector, '.') # Placeholder extraction split = @property.split('.') @property = split[0] @placeholder = split.slice(1).join('.') @selector = @property return @ import prototype-private.coffee import prototype-public.coffee