-
Notifications
You must be signed in to change notification settings - Fork 40
Internal: Changed the way of data serialization. #1493
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -107,6 +107,17 @@ export default class AttributeOperation extends Operation { | |||
return new AttributeOperation( this.range, this.key, this.newValue, this.oldValue, this.baseVersion + 1 ); | ||||
} | ||||
|
||||
/** | ||||
* @inheritDoc | ||||
*/ | ||||
toJSON() { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder here... Theoretically, values could be arrays or objects. Will those be cloned? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW... maybe we should just give up that and allow only for string, numeral and boolean values for attributes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔I'm afraid in a case of objects we pass a reference to the value instead of cloning.
We can think about dropping other formats than primitives but we don't know if someone has already used it with objects or arrays. |
||||
const json = super.toJSON(); | ||||
|
||||
json.range = this.range.toJSON(); | ||||
|
||||
return json; | ||||
} | ||||
|
||||
/** | ||||
* @inheritDoc | ||||
*/ | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,6 +163,21 @@ export default class WrapOperation extends Operation { | |
_move( wrappedRange, targetPosition ); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
toJSON() { | ||
const json = super.toJSON(); | ||
|
||
json.position = this.position.toJSON(); | ||
|
||
if ( json.graveyardPosition ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrap operation can have graveyard position or element. Shouldn't we do |
||
json.graveyardPosition = this.graveyardPosition.toJSON(); | ||
} | ||
|
||
return json; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -790,6 +790,17 @@ export default class Position { | |
return combined; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
toJSON() { | ||
return { | ||
root: this.root.toJSON(), | ||
path: Array.from( this.path ), | ||
stickiness: this.stickiness | ||
}; | ||
} | ||
|
||
/** | ||
* Creates position at the given location. The location can be specified as: | ||
* | ||
|
@@ -915,7 +926,7 @@ export default class Position { | |
*/ | ||
static fromJSON( json, doc ) { | ||
if ( json.root === '$graveyard' ) { | ||
const pos = new Position( doc.graveyard, json.path ); | ||
const pos = new Position( doc.graveyard, Array.from( json.path ) ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you need this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be removed. |
||
pos.stickiness = json.stickiness; | ||
|
||
return pos; | ||
|
@@ -934,7 +945,7 @@ export default class Position { | |
); | ||
} | ||
|
||
const pos = new Position( doc.getRoot( json.root ), json.path ); | ||
const pos = new Position( doc.getRoot( json.root ), Array.from( json.path ) ); | ||
pos.stickiness = json.stickiness; | ||
|
||
return pos; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A comment is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.