neft
Version:
Universal Platform
90 lines (69 loc) • 2.49 kB
text/coffeescript
log = require 'src/log'
utils = require 'src/utils'
assert = require 'src/assert'
signal = require 'src/signal'
{Emitter} = signal
{emitSignal} = Emitter
assert = assert.scope 'View.Scripts'
class FileContext extends Emitter
propOpts = utils.CONFIGURABLE | utils.WRITABLE
constructor: ->
super()
utils.defineProperty @, '_signals', propOpts,
utils.defineProperty @, 'node', propOpts, null
utils.defineProperty @, 'props', propOpts, null
utils.defineProperty @, 'refs', propOpts, null
utils.defineProperty @, 'context', propOpts, null
utils.defineProperty @, 'state', propOpts, null
utils.defineProperty @::, 'constructor', propOpts, @
Emitter.createSignal @, 'onCreate'
Emitter.createSignal @, 'onBeforeRender'
Emitter.createSignal @, 'onRender'
Emitter.createSignal @, 'onBeforeRevert'
Emitter.createSignal @, 'onRevert'
module.exports = (File) -> class Scripts
= 'Scripts'
= 'File.Scripts'
= {}
JSON_CTOR_ID = = File.JSON_CTORS.push(Scripts) - 1
i = 1
JSON_NAMES = i++
JSON_ARGS_LENGTH = = i
= (file, arr, obj) ->
unless obj
obj = new Scripts file, arr[JSON_NAMES]
obj
constructor: (, ) ->
assert.instanceOf , File
assert.isArray
`//<development>`
if is Scripts
Object.seal @
`//</development>`
.scope = ()
createScope: ->
ctx = new FileContext
for name in
func = Scripts.scripts[name]
func.call ctx
ctx
createCloneScope: (file) ->
{names} = @
scope = Object.create .scope
propOpts = utils.CONFIGURABLE | utils.WRITABLE
utils.defineProperty scope, 'node', propOpts, file.node
utils.defineProperty scope, 'props', propOpts, file.inputProps
utils.defineProperty scope, 'refs', propOpts, file.inputRefs
utils.defineProperty scope, 'context', utils.CONFIGURABLE, ->
file.context
, null
utils.defineProperty scope, 'state', propOpts, null
emitSignal scope, 'onCreate'
scope
toJSON: (key, arr) ->
unless arr
arr = new Array JSON_ARGS_LENGTH
arr[0] = JSON_CTOR_ID
arr[JSON_NAMES] =
arr