no more Immutable types :)
This commit is contained in:
parent
f1f710b269
commit
e54402e842
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
@ -111,7 +111,7 @@ module.exports = (HB)->
|
||||
else
|
||||
throw new Error "The #{content.constructor.name}-type is not (yet) supported in Yatta."
|
||||
else
|
||||
super name, (new types.ImmutableObject undefined, content).execute()
|
||||
super name, content
|
||||
else # is this even necessary ? I have to define every type anyway.. (see Number type below)
|
||||
super name
|
||||
|
||||
@ -139,7 +139,7 @@ module.exports = (HB)->
|
||||
|
||||
types.Number = {}
|
||||
types.Number.create = (content)->
|
||||
(new types.ImmutableObject undefined, content).execute()
|
||||
content
|
||||
|
||||
text_types
|
||||
|
||||
|
@ -31,27 +31,20 @@ module.exports = (HB)->
|
||||
# @see JsonTypes.val
|
||||
#
|
||||
val: (name, content)->
|
||||
if content?
|
||||
if arguments.length > 1
|
||||
@retrieveSub(name).replace content
|
||||
@
|
||||
else if name?
|
||||
prop = @map[name]
|
||||
if prop? and not prop.isContentDeleted()
|
||||
obj = prop.val()
|
||||
if obj instanceof types.ImmutableObject
|
||||
obj.val()
|
||||
else
|
||||
obj
|
||||
prop.val()
|
||||
else
|
||||
undefined
|
||||
else
|
||||
result = {}
|
||||
for name,o of @map
|
||||
if not o.isContentDeleted()
|
||||
obj = o.val()
|
||||
if obj instanceof types.ImmutableObject # or obj instanceof MapManager TODO: do you want deep json?
|
||||
obj = obj.val()
|
||||
result[name] = obj
|
||||
result[name] = o.val()
|
||||
result
|
||||
|
||||
delete: (name)->
|
||||
@ -253,7 +246,11 @@ module.exports = (HB)->
|
||||
# @param {Object} uid A unique identifier. If uid is undefined, a new uid will be created.
|
||||
#
|
||||
constructor: (content, parent, uid, prev, next, origin, is_deleted)->
|
||||
@saveOperation 'content', content
|
||||
# see encode to see, why we are doing it this way
|
||||
if content? and content.creator?
|
||||
@saveOperation 'content', content
|
||||
else
|
||||
@content = content
|
||||
@saveOperation 'parent', parent
|
||||
super uid, prev, next, origin # Parent is already saved by Replaceable
|
||||
@is_deleted = is_deleted
|
||||
@ -270,9 +267,9 @@ module.exports = (HB)->
|
||||
res = super
|
||||
if @content?
|
||||
if @next_cl.type isnt "Delimiter"
|
||||
@content.deleteAllObservers()
|
||||
@content.applyDelete()
|
||||
@content.dontSync()
|
||||
@content.deleteAllObservers?()
|
||||
@content.applyDelete?()
|
||||
@content.dontSync?()
|
||||
@content = null
|
||||
res
|
||||
|
||||
@ -321,7 +318,6 @@ module.exports = (HB)->
|
||||
json =
|
||||
{
|
||||
'type': @type
|
||||
'content': @content?.getUid()
|
||||
'parent' : @parent.getUid()
|
||||
'prev': @prev_cl.getUid()
|
||||
'next': @next_cl.getUid()
|
||||
@ -329,6 +325,14 @@ module.exports = (HB)->
|
||||
'uid' : @getUid()
|
||||
'is_deleted': @is_deleted
|
||||
}
|
||||
if @content instanceof types.Operation
|
||||
json['content'] = @content.getUid()
|
||||
else
|
||||
# This could be a security concern.
|
||||
# Throw error if the users wants to trick us
|
||||
if @content? and @content.creator?
|
||||
throw new Error "You must not set creator here!"
|
||||
json['content'] = @content
|
||||
json
|
||||
|
||||
types.Replaceable.parse = (json)->
|
||||
|
@ -181,7 +181,7 @@ module.exports = (HB)->
|
||||
list.insert 0, content
|
||||
list
|
||||
else if (not mutable?) or (mutable is "immutable")
|
||||
(new types.ImmutableObject undefined, content).execute()
|
||||
content
|
||||
else
|
||||
throw new Error "Specify either \"mutable\" or \"immutable\"!!"
|
||||
|
||||
@ -377,7 +377,7 @@ module.exports = (HB)->
|
||||
word.insert 0, content
|
||||
word
|
||||
else if (not mutable?) or (mutable is "immutable")
|
||||
(new types.ImmutableObject undefined, content).execute()
|
||||
content
|
||||
else
|
||||
throw new Error "Specify either \"mutable\" or \"immutable\"!!"
|
||||
|
||||
|
@ -130,6 +130,16 @@ describe "JsonFramework", ->
|
||||
expect(@yTest.getSomeUser().val('object').val('q')).to.equal "rr"
|
||||
expect(@yTest.getSomeUser().val('null') is null).to.be.ok
|
||||
|
||||
it "handles immutables and primitive data types (2)", ->
|
||||
@yTest.users[0].val('string', "text", "immutable")
|
||||
@yTest.users[1].val('number', 4, "immutable")
|
||||
@yTest.users[2].val('object', {q:"rr"}, "immutable")
|
||||
@yTest.users[0].val('null', null)
|
||||
@yTest.compareAll()
|
||||
expect(@yTest.getSomeUser().val('string')).to.equal "text"
|
||||
expect(@yTest.getSomeUser().val('number')).to.equal 4
|
||||
expect(@yTest.getSomeUser().val('object').val('q')).to.equal "rr"
|
||||
expect(@yTest.getSomeUser().val('null') is null).to.be.ok
|
||||
|
||||
it "Observers work on JSON Types (add type observers, local and foreign)", ->
|
||||
u = @yTest.users[0]
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user