neft
Version:
Universal Platform
75 lines (56 loc) • 1.91 kB
text/coffeescript
'use strict'
eventLoop = require 'src/eventLoop'
Binding = require 'src/binding'
module.exports = (impl) ->
class RendererBinding extends Binding
pool = []
= (obj, prop, binding, ctx) ->
if elem = pool.pop()
RendererBinding.call elem, obj, prop, binding, ctx
RendererBinding.New obj, prop, binding, ctx, elem
= (obj, prop, binding, ctx, target) ->
target ?= new RendererBinding obj, prop, binding, ctx
Binding.New binding, ctx, target
target.update()
target
constructor: (, , binding, ctx) ->
super binding, ctx
getItemById: (item) ->
if typeof item is 'object'
item
else if item is 'this'
else if item is 'windowItem'
impl.windowItem
else
impl.Renderer[item] or null
update: ->
eventLoop.lock()
super()
eventLoop.release()
return
getValue: ->
[]
setValue: (val) ->
if not val? or val isnt val
val =
[] = val
return
getLoopDetectedErrorMessage: ->
"""
Potential loop detected. \
Property binding '#{@prop}' on '#{@item.toString()}' has been disabled.
"""
destroy: ->
# remove from the list
._impl.bindings[] = null
super()
pool.push @
return
setItemBinding: (prop, binding, ctx) ->
data =
data.bindings ?= {}
data.bindings[prop]?.destroy()
if binding?
data.bindings[prop] = RendererBinding.factory @, prop, binding, ctx
return