neft
Version:
Universal Platform
68 lines (53 loc) • 1.76 kB
text/coffeescript
utils = require 'src/utils'
assert = require 'src/assert'
module.exports = (File) -> class Log
= 'Log'
= 'File.Log'
JSON_CTOR_ID = = File.JSON_CTORS.push(Log) - 1
i = 1
JSON_NODE = i++
JSON_ARGS_LENGTH = = i
= (file, arr, obj) ->
unless obj
node = file.node.getChildByAccessPath arr[JSON_NODE]
obj = new Log file, node
obj
listenOnTextChange = (node, log) ->
if node instanceof File.Element.Text
node.onTextChange log.log, log
else
for child in node.children
listenOnTextChange child, log
return
constructor: (, ) ->
assert.instanceOf , File
assert.instanceOf , File.Element
.onPropsChange , @
listenOnTextChange , @
`//<development>`
if is Log
Object.preventExtensions @
`//</development>`
render: ->
if utils.isEmpty(.props)
console.log .stringifyChildren()
else
{props} =
log = [.stringifyChildren()]
for key, val of props when props.hasOwnProperty(key)
log.push key, '=', val
console.log.apply console, log
return
log: ->
if .isRendered
()
clone: (original, file) ->
node = original.node.getCopiedElement , file.node
new Log file, node
toJSON: (key, arr) ->
unless arr
arr = new Array JSON_ARGS_LENGTH
arr[0] = JSON_CTOR_ID
arr[JSON_NODE] = .getAccessPath .node
arr