neft
Version:
Universal Platform
64 lines (49 loc) • 1.76 kB
text/coffeescript
assert = require 'src/assert'
module.exports = (File) -> class Condition
= 'Condition'
= 'File.Condition'
JSON_CTOR_ID = = File.JSON_CTORS.push(Condition) - 1
i = 1
JSON_NODE = i++
JSON_ELSE_NODE = i++
JSON_ARGS_LENGTH = = i
= (file, arr, obj) ->
unless obj
node = file.node.getChildByAccessPath arr[JSON_NODE]
if arr[JSON_ELSE_NODE]
elseNode = file.node.getChildByAccessPath arr[JSON_ELSE_NODE]
obj = new Condition file, node, elseNode
obj
onPropsChange = (name) ->
if name is 'n-if'
()
return
constructor: (, , =null) ->
assert.instanceOf , File
assert.instanceOf , File.Element
if elseNode?
assert.instanceOf , File.Element
.onPropsChange onPropsChange, @
`//<development>`
if is Condition
Object.preventExtensions @
`//</development>`
update: ->
visible = .visible = !!.props['n-if']
?.visible = not visible
return
render: ->
()
clone: (original, file) ->
node = original.node.getCopiedElement , file.node
if
elseNode = original.node.getCopiedElement , file.node
new Condition file, node, elseNode
toJSON: (key, arr) ->
unless arr
arr = new Array JSON_ARGS_LENGTH
arr[0] = JSON_CTOR_ID
arr[JSON_NODE] = .getAccessPath .node
arr[JSON_ELSE_NODE] = ?.getAccessPath .node
arr