changing the GC algorith. Only operations left to an deleted insertion can be garbage collected. (incomplete!)

This commit is contained in:
DadaMonad 2015-01-08 12:10:57 +00:00
parent af3cd2361a
commit a1b07f84ea
14 changed files with 244 additions and 33065 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -3,7 +3,7 @@
<head> <head>
<meta charset=utf-8 /> <meta charset=utf-8 />
<title>PeerJs Json Example</title> <title>PeerJs Json Example</title>
<script src="../../../Connector/xmpp-connector/xmpp-connector.js"></script> <script src="../../../Yatta-Connectors/xmpp-connector/xmpp-connector.js"></script>
<script src="../../build/browser/yatta.js"></script> <script src="../../build/browser/yatta.js"></script>
<script src="./index.js"></script> <script src="./index.js"></script>
</head> </head>

View File

@ -1,11 +1,11 @@
<link rel="import" href="../../yatta-element.html"> <link rel="import" href="../../yatta-element.html">
<link rel="import" href="../../../Connector/strophe-connector/strophe-connector.html"> <link rel="import" href="../../../Yatta-Connectors/xmpp-connector/xmpp-connector.html">
<link rel="import" href="../../bower_components/paper-slider/paper-slider.html"> <link rel="import" href="../../bower_components/paper-slider/paper-slider.html">
<polymer-element name="yatta-test" attributes="yatta connector stuff"> <polymer-element name="yatta-test" attributes="yatta connector stuff">
<template> <template>
<strophe-connector id="connector" connector={{connector}}></strophe-connector> <xmpp-connector id="connector" connector={{connector}}></xmpp-connector>
<yatta-element connector={{connector}} val={{yatta}}> <yatta-element connector={{connector}} val={{yatta}}>
<yatta-property name="slider" val={{slider}}> <yatta-property name="slider" val={{slider}}>
</yatta-property> </yatta-property>

View File

@ -77,15 +77,7 @@ gulp.task 'mocha', ->
gulp.src files.test, { read: false } gulp.src files.test, { read: false }
.pipe plumber() .pipe plumber()
.pipe mocha {reporter : 'list'} .pipe mocha {reporter : 'list'}
.pipe ignore.include '**/*.coffee'
.pipe browserify
transform: ['coffeeify']
extensions: ['.coffee']
debug: true
.pipe rename
extname: ".js"
.pipe gulp.dest 'build/test/'
.pipe gulpif '!**/', git.add({args : "-A"})
gulp.task 'lint', -> gulp.task 'lint', ->
gulp.src files.all gulp.src files.all

View File

@ -10,6 +10,9 @@ adaptConnector = (connector, engine, HB, execution_listener)->
if o.uid.creator is HB.getUserId() and (typeof o.uid.op_number isnt "string") if o.uid.creator is HB.getUserId() and (typeof o.uid.op_number isnt "string")
connector.broadcast o connector.broadcast o
if connector.invokeSync?
HB.setInvokeSyncHandler connector.invokeSync
execution_listener.push send_ execution_listener.push send_
# For the XMPPConnector: lets send it as an array # For the XMPPConnector: lets send it as an array
# therefore, we have to restructure it later # therefore, we have to restructure it later
@ -43,6 +46,5 @@ adaptConnector = (connector, engine, HB, execution_listener)->
if op.uid.creator isnt HB.getUserId() if op.uid.creator isnt HB.getUserId()
engine.applyOp op engine.applyOp op
HB.setInvokeSyncHandler connector.invokeSync
module.exports = adaptConnector module.exports = adaptConnector

View File

@ -273,18 +273,18 @@ module.exports = (HB)->
if o? if o?
@deleted_by.push o @deleted_by.push o
garbagecollect = false garbagecollect = false
if not (@prev_cl? and @next_cl?) or @prev_cl.isDeleted() if @next_cl.isDeleted()
garbagecollect = true garbagecollect = true
super garbagecollect super garbagecollect
if callLater if callLater
@callOperationSpecificDeleteEvents(o) @callOperationSpecificDeleteEvents(o)
if @next_cl?.isDeleted() if @prev_cl?.isDeleted()
# garbage collect next_cl # garbage collect prev_cl
@next_cl.applyDelete() @prev_cl.applyDelete()
cleanup: ()-> cleanup: ()->
# TODO: Debugging # TODO: Debugging
if @prev_cl?.isDeleted() if @next_cl?.isDeleted()
# delete all ops that delete this insertion # delete all ops that delete this insertion
for d in @deleted_by for d in @deleted_by
d.cleanup() d.cleanup()
@ -300,7 +300,8 @@ module.exports = (HB)->
@prev_cl.next_cl = @next_cl @prev_cl.next_cl = @next_cl
@next_cl.prev_cl = @prev_cl @next_cl.prev_cl = @prev_cl
super super
else if @next_cl? and @prev_cl?
throw new Error "This insertion was not supposed to be deleted!"
# #
# @private # @private

View File

@ -343,12 +343,13 @@ module.exports = (HB)->
# @param {ReplaceManager} parent Used to replace this Replaceable with another one. # @param {ReplaceManager} parent Used to replace this Replaceable with another one.
# @param {Object} uid A unique identifier. If uid is undefined, a new uid will be created. # @param {Object} uid A unique identifier. If uid is undefined, a new uid will be created.
# #
constructor: (content, parent, uid, prev, next, origin)-> constructor: (content, parent, uid, prev, next, origin, is_deleted)->
@saveOperation 'content', content @saveOperation 'content', content
@saveOperation 'parent', parent @saveOperation 'parent', parent
if not (prev? and next?) if not (prev? and next?)
throw new Error "You must define prev, and next for Replaceable-types!" throw new Error "You must define prev, and next for Replaceable-types!"
super uid, prev, next, origin super uid, prev, next, origin
@is_deleted = is_deleted
type: "Replaceable" type: "Replaceable"
@ -379,12 +380,13 @@ module.exports = (HB)->
callOperationSpecificInsertEvents: ()-> callOperationSpecificInsertEvents: ()->
if @next_cl.type is "Delimiter" and @prev_cl.type isnt "Delimiter" if @next_cl.type is "Delimiter" and @prev_cl.type isnt "Delimiter"
# this replaces another Replaceable # this replaces another Replaceable
old_value = @prev_cl.content if not @is_deleted # When this is received from the HB, this could already be deleted!
@parent.callEventDecorator [ old_value = @prev_cl.content
type: "update" @parent.callEventDecorator [
changedBy: @uid.creator type: "update"
oldValue: old_value changedBy: @uid.creator
] oldValue: old_value
]
@prev_cl.applyDelete() @prev_cl.applyDelete()
else if @next_cl.type isnt "Delimiter" else if @next_cl.type isnt "Delimiter"
# This won't be recognized by the user, because another # This won't be recognized by the user, because another
@ -417,6 +419,7 @@ module.exports = (HB)->
'prev': @prev_cl.getUid() 'prev': @prev_cl.getUid()
'next': @next_cl.getUid() 'next': @next_cl.getUid()
'uid' : @getUid() 'uid' : @getUid()
'is_deleted': @is_deleted
} }
if @origin? and @origin isnt @prev_cl if @origin? and @origin isnt @prev_cl
json["origin"] = @origin.getUid() json["origin"] = @origin.getUid()
@ -430,8 +433,9 @@ module.exports = (HB)->
'prev': prev 'prev': prev
'next': next 'next': next
'origin' : origin 'origin' : origin
'is_deleted': is_deleted
} = json } = json
new Replaceable content, parent, uid, prev, next, origin new Replaceable content, parent, uid, prev, next, origin, is_deleted
types['ListManager'] = ListManager types['ListManager'] = ListManager
types['MapManager'] = MapManager types['MapManager'] = MapManager

View File

@ -124,10 +124,6 @@ module.exports = (HB)->
type: "WordType" type: "WordType"
applyDelete: ()-> applyDelete: ()->
for textfield in @textfields
textfield.onkeypress = null
textfield.onpaste = null
textfield.oncut = null
o = @beginning o = @beginning
while o? while o?
o.applyDelete() o.applyDelete()
@ -141,9 +137,10 @@ module.exports = (HB)->
@insertAfter @end.prev_cl, content @insertAfter @end.prev_cl, content
insertAfter: (left, content)-> insertAfter: (left, content)->
while left.isDeleted()
left = left.prev_cl # find the first character to the left, that is not deleted. Case position is 0, its the Delimiter.
right = left.next_cl right = left.next_cl
while right.isDeleted()
right = right.next_cl # find the first character to the right, that is not deleted. In the case that position is 0, its the Delimiter.
left = right.prev_cl
if content.type? if content.type?
(new TextInsert content, undefined, left, right).execute() (new TextInsert content, undefined, left, right).execute()
else else
@ -243,6 +240,10 @@ module.exports = (HB)->
# consume all text-insert changes. # consume all text-insert changes.
textfield.onkeypress = (event)-> textfield.onkeypress = (event)->
if word.is_deleted
# if word is deleted, do not do anything ever again
textfield.onkeypress = null
return true
char = null char = null
if event.key? if event.key?
if event.charCode is 32 if event.charCode is 32
@ -265,8 +266,16 @@ module.exports = (HB)->
event.preventDefault() event.preventDefault()
textfield.onpaste = (event)-> textfield.onpaste = (event)->
if word.is_deleted
# if word is deleted, do not do anything ever again
textfield.onpaste = null
return true
event.preventDefault() event.preventDefault()
textfield.oncut = (event)-> textfield.oncut = (event)->
if word.is_deleted
# if word is deleted, do not do anything ever again
textfield.oncut = null
return true
event.preventDefault() event.preventDefault()
# #
@ -277,6 +286,10 @@ module.exports = (HB)->
# Every browser supports keyCode. Let's stick with it for now.. # Every browser supports keyCode. Let's stick with it for now..
# #
textfield.onkeydown = (event)-> textfield.onkeydown = (event)->
if word.is_deleted
# if word is deleted, do not do anything ever again
textfield.onkeydown = null
return true
pos = Math.min textfield.selectionStart, textfield.selectionEnd pos = Math.min textfield.selectionStart, textfield.selectionEnd
diff = Math.abs(textfield.selectionEnd - textfield.selectionStart) diff = Math.abs(textfield.selectionEnd - textfield.selectionStart)
if event.keyCode? and event.keyCode is 8 # Backspace if event.keyCode? and event.keyCode is 8 # Backspace

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long