adding yatta-element

This commit is contained in:
DadaMonad
2015-01-02 22:43:43 +00:00
parent 6790355232
commit 877365d00c
39 changed files with 31984 additions and 0 deletions

52
lib/yatta-element.coffee Normal file
View File

@@ -0,0 +1,52 @@
Yatta = require './yatta'
bindToChildren = (that)->
for i in [0...that.children.length]
attr = that.children.item(i)
if attr.name?
attr.val = that.val.val(attr.name)
that.val.observe (events)->
for event in events
if event.name?
for i in [0...that.children.length]
attr = that.children.item(i)
if attr.name? and attr.name is event.name
newVal = that.val.val(attr.name)
if attr.val isnt newVal
attr.val = newVal
Polymer "yatta-element",
ready: ()->
if @connector?
@val = new Yatta @connector
bindToChildren @
else if @val?
bindToChildren @
valChanged: ()->
if @val? and @val.type is "JsonType"
bindToChildren @
Polymer "yatta-property",
ready: ()->
if @val? and @name?
if @val.constructor is Object
@val = @parentElement.val(@name,@val).val(@name)
# TODO: please use instanceof instead of .type,
# since it is more safe (consider someone putting a custom Object type here)
else if typeof @val is "string"
@parentElement.val(@name,@val)
if @val.type is "JsonType"
bindToChildren @
valChanged: ()->
if @val? and @name?
if @val.constructor is Object
@val = @parentElement.val.val(@name,@val).val(@name)
# TODO: please use instanceof instead of .type,
# since it is more safe (consider someone putting a custom Object type here)
if @val.type is "JsonType"
bindToChildren @

41
lib/yatta.coffee Normal file
View File

@@ -0,0 +1,41 @@
json_types_uninitialized = require "./Types/JsonTypes"
HistoryBuffer = require "./HistoryBuffer"
Engine = require "./Engine"
adaptConnector = require "./ConnectorAdapter"
createYatta = (connector)->
user_id = connector.id # TODO: change to getUniqueId()
HB = new HistoryBuffer user_id
type_manager = json_types_uninitialized HB
types = type_manager.types
#
# Framework for Json data-structures.
# Known values that are supported:
# * String
# * Integer
# * Array
#
class Yatta extends types.JsonType
#
# @param {String} user_id Unique id of the peer.
# @param {Connector} Connector the connector class.
#
constructor: ()->
@connector = connector
@HB = HB
@types = types
@engine = new Engine @HB, type_manager.parser
adaptConnector @connector, @engine, @HB, type_manager.execution_listener
super
getConnector: ()->
@connector
return new Yatta(HB.getReservedUniqueIdentifier()).execute()
module.exports = createYatta
if window? and not window.Yatta?
window.Yatta = createYatta