neft
Version:
Universal Platform
84 lines (66 loc) • 2.38 kB
text/coffeescript
assert = require 'src/assert'
utils = require 'src/utils'
log = require 'src/log'
assert = assert.scope 'View.StateChange'
log = log.scope 'View', 'StateChange'
module.exports = (File) -> class StateChange
= 'StateChange'
= 'File.StateChange'
JSON_CTOR_ID = = File.JSON_CTORS.push(StateChange) - 1
i = 1
JSON_NODE = i++
JSON_TARGET = i++
JSON_NAME = i++
JSON_ARGS_LENGTH = = i
= (file, arr, obj) ->
unless obj
node = file.node.getChildByAccessPath arr[JSON_NODE]
target = file.node.getChildByAccessPath arr[JSON_TARGET]
obj = new StateChange file, node, target, arr[JSON_NAME]
obj
constructor: (, , , ) ->
assert.instanceOf , File
assert.instanceOf , File.Element
assert.instanceOf , File.Element
assert.isString
assert.notLengthOf , 0
= undefined
()
.onVisibleChange onVisibleChange, @
.onPropsChange onPropsChange, @
`//<development>`
if is StateChange
Object.seal @
`//</development>`
update: ->
{inputState} =
val = if .visible then .props.value else
if val isnt undefined
inputState.set , val
else if inputState.has()
inputState.pop
return
render: ->
= .inputState[]
()
onVisibleChange = ->
()
onPropsChange = (name, oldValue) ->
if name is 'name'
throw new Error 'Dynamic <state /> name is not yet supported'
else if name is 'value'
()
return
clone: (original, file) ->
node = original.node.getCopiedElement , file.node
target = original.node.getCopiedElement , file.node
new StateChange file, node, target,
toJSON: (key, arr) ->
unless arr
arr = new Array JSON_ARGS_LENGTH
arr[0] = JSON_CTOR_ID
arr[JSON_NODE] = .getAccessPath .node
arr[JSON_TARGET] = .getAccessPath .node
arr[JSON_NAME] =
arr