neft
Version:
Universal Platform
68 lines (53 loc) • 1.83 kB
text/coffeescript
'use strict'
utils = require 'src/utils'
assert = require 'src/assert'
log = require 'src/log'
module.exports = (File) -> class PropsToSet
= 'PropsToSet'
= 'File.PropsToSet'
JSON_CTOR_ID = = File.JSON_CTORS.push(PropsToSet) - 1
i = 1
JSON_NODE = i++
JSON_ATTRS = i++
JSON_ARGS_LENGTH = = i
= (file, arr, obj) ->
unless obj
node = file.node.getChildByAccessPath arr[JSON_NODE]
obj = new PropsToSet file, node, arr[JSON_ATTRS]
obj
constructor: (, , ) ->
assert.instanceOf , File
assert.instanceOf , File.Element
assert.isPlainObject
# set current props
for prop of
if .props[prop]?
prop, null
# listen on changes
.onPropsChange , @
`//<development>`
if is PropsToSet
Object.preventExtensions @
`//</development>`
setProp: (prop, oldValue) ->
unless [prop]
return
val = .props[prop]
if typeof [prop] is 'function' and [prop].connect
if typeof oldValue is 'function'
[prop].disconnect oldValue
if typeof val is 'function'
[prop] val
else
[prop] = val
return
clone: (original, file) ->
node = original.node.getCopiedElement , file.node
new PropsToSet file, node,
toJSON: (key, arr) ->
unless arr
arr = new Array JSON_ARGS_LENGTH
arr[0] = JSON_CTOR_ID
arr[JSON_NODE] = .getAccessPath .node
arr[JSON_ATTRS] =
arr