neft
Version:
Universal Platform
72 lines (55 loc) • 2.06 kB
text/coffeescript
assert = require 'src/assert'
utils = require 'src/utils'
module.exports = (File, Input) -> class InputProp extends Input
= 'InputProp'
= 'File.Input.Prop'
JSON_CTOR_ID = = File.JSON_CTORS.push(InputProp) - 1
i = Input.JSON_ARGS_LENGTH
{JSON_NODE, JSON_TEXT, JSON_BINDING} = Input
JSON_ATTR_NAME = i++
JSON_ARGS_LENGTH = = i
= (file, arr, obj) ->
unless obj
node = file.node.getChildByAccessPath arr[JSON_NODE]
obj = new InputProp file, node, arr[JSON_TEXT], arr[JSON_BINDING], arr[JSON_ATTR_NAME]
obj
isHandler = (name) ->
/^on[A-Z]|\:on[A-Z][A-Za-z0-9_$]*$/.test name
constructor: (file, node, text, bindingConfig, ) ->
assert.isString
assert.notLengthOf , 0
Input.call @, file, node, text, bindingConfig
if isHandler()
= createHandlerFunc @
node.props.set ,
else
= null
if file.isClone
()
`//<development>`
if is InputProp
Object.seal @
`//</development>`
getValue: ->
.props[]
setValue: (val) ->
.props.set , val
createHandlerFunc = (input) ->
(arg1, arg2) ->
unless input.file.isRendered
return
r = input.bindingConfig.func.apply input, input.file.inputArgs
if typeof r is 'function'
r.call @, arg1, arg2
return
clone: (original, file) ->
node = original.node.getCopiedElement , file.node
new InputProp file, node, , ,
toJSON: (key, arr) ->
unless arr
arr = new Array JSON_ARGS_LENGTH
arr[0] = JSON_CTOR_ID
super key, arr
arr[JSON_ATTR_NAME] =
arr