neft
Version:
Universal Platform
178 lines (144 loc) • 4.72 kB
text/coffeescript
'use strict'
utils = require 'src/utils'
assert = require 'src/assert'
log = require 'src/log'
signal = require 'src/signal'
eventLoop = require 'src/eventLoop'
Dict = require 'src/dict'
List = require 'src/list'
Binding = require 'src/binding'
assert = assert.scope 'View.Input'
log = log.scope 'View', 'Input'
class DocumentBinding extends Binding
= (binding, ctx, target) ->
target ?= new DocumentBinding binding, ctx
Binding.New binding, ctx, target
constructor: (binding, ctx) ->
super binding, ctx
= ctx.file.inputArgs
`//<development>`
= false
= false
`//</development>`
getItemById: (item) ->
if item is 'this'
else if item is 'refs'
[0]
else if item is 'props'
[1]
else if item is 'state'
[2]
`//<development>`
failCheckQueue = []
failCheckQueuePending = false
checkFails = ->
while binding = failCheckQueue.pop()
err = failCheckQueue.pop()
if binding.failed
log.error "Error in '#{binding.ctx.text}', file '#{binding.ctx.file.path}':\n#{err}"
binding.failCheckPending = false
failCheckQueuePending = false
return
onError: (err) ->
= true
unless
= true
failCheckQueue.push err, @
unless failCheckQueuePending
failCheckQueuePending = true
setImmediate checkFails
return
`//</development>`
update: ->
# disable updates for reverted files
if not .isRendered
return
`//<development>`
= false
`//</development>`
eventLoop.lock()
super()
eventLoop.release()
return
getValue: ->
.getValue()
setValue: (val) ->
.setValue val
module.exports = (File) -> class Input extends signal.Emitter
{Element} = File
{Tag} = Element
= 'Input'
= 'File.Input'
JSON_CTOR_ID = = File.JSON_CTORS.push(Input) - 1
i = 1
JSON_NODE = = i++
JSON_TEXT = = i++
JSON_BINDING = = i++
JSON_ARGS_LENGTH = = i
= (file, arr, obj) ->
unless obj
node = file.node.getChildByAccessPath arr[JSON_NODE]
obj = new Input file, node, arr[JSON_TEXT], arr[JSON_BINDING]
obj
RE = = new RegExp '([^$]*)\\${([^}]*)}([^$]*)', 'gm'
= (str) ->
RE.lastIndex = 0
RE.test str
if process.env.NEFT_PLATFORM is 'node'
= require('./input/parser').parse
initBindingConfig = (cfg) ->
cfg.func ?= new Function 'refs', 'props', 'state', cfg.body
cfg.tree ?= [cfg.func, cfg.connections]
return
constructor: (, , , ) ->
assert.instanceOf , File
assert.instanceOf , File.Element
assert.isString
assert.isObject
super()
= false
= null
= null
= null
initBindingConfig
`//<development>`
if is Input
Object.seal @
`//</development>`
signal.Emitter.createSignal @, 'onTargetChange'
signal.Emitter.createSignal @, 'onContextChange'
registerBinding: ->
assert.isNotDefined
= DocumentBinding.New .tree, @
return
render: ->
oldTarget =
oldContext =
= .scope
= .context
if oldTarget isnt
.emit()
if oldContext isnt
.emit()
= true
?.update()
return
revert: ->
= false
return
clone: (original, file) ->
node = original.node.getCopiedElement , file.node
new Input 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_TEXT] =
arr[JSON_BINDING] =
body: .body
connections: .connections
arr
= require('./input/text.coffee') File, @
= require('./input/prop.coffee') File, @