This repository was archived by the owner on Jun 26, 2020. It is now read-only.
File tree 3 files changed +27
-1
lines changed
3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import ModelElement from './element';
18
18
import ModelRange from './range' ;
19
19
import ModelPosition from './position' ;
20
20
import ModelSelection from './selection' ;
21
+ import OperationFactory from './operation/operationfactory' ;
21
22
22
23
import insertContent from './utils/insertcontent' ;
23
24
import deleteContent from './utils/deletecontent' ;
@@ -755,6 +756,18 @@ export default class Model {
755
756
return new Batch ( type ) ;
756
757
}
757
758
759
+ /**
760
+ * Creates an operation instance from a JSON object (parsed JSON string).
761
+ *
762
+ * This is an alias for {@link module:engine/model/operation/operationfactory~OperationFactory#fromJSON}.
763
+ *
764
+ * @param {Object } json Deserialized JSON object.
765
+ * @returns {module:engine/model/operation/operation~Operation }
766
+ */
767
+ createOperationFromJSON ( json ) {
768
+ return OperationFactory . fromJSON ( json , this . document ) ;
769
+ }
770
+
758
771
/**
759
772
* Removes all events listeners set by model instance and destroys {@link module:engine/model/document~Document}.
760
773
*/
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ operations[ MergeOperation.className ] = MergeOperation;
37
37
*/
38
38
export default class OperationFactory {
39
39
/**
40
- * Creates concrete `Operation` object from deserialized object, i.e. from parsed JSON string.
40
+ * Creates an operation instance from a JSON object ( parsed JSON string) .
41
41
*
42
42
* @param {Object } json Deserialized JSON object.
43
43
* @param {module:engine/model/document~Document } document Document on which this operation will be applied.
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import ModelPosition from '../../src/model/position';
11
11
import ModelSelection from '../../src/model/selection' ;
12
12
import ModelDocumentFragment from '../../src/model/documentfragment' ;
13
13
import Batch from '../../src/model/batch' ;
14
+ import NoOperation from '../../src/model/operation/nooperation' ;
14
15
import { getData , setData , stringify } from '../../src/dev-utils/model' ;
15
16
import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils' ;
16
17
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror' ;
@@ -826,6 +827,18 @@ describe( 'Model', () => {
826
827
} ) ;
827
828
} ) ;
828
829
830
+ describe ( 'createOperationFromJson()' , ( ) => {
831
+ it ( 'should create operation from JSON' , ( ) => {
832
+ const operation = model . createOperationFromJSON ( {
833
+ __className : 'NoOperation' ,
834
+ baseVersion : 0
835
+ } ) ;
836
+
837
+ expect ( operation ) . to . instanceof ( NoOperation ) ;
838
+ expect ( operation . baseVersion ) . to . equal ( 0 ) ;
839
+ } ) ;
840
+ } ) ;
841
+
829
842
describe ( 'destroy()' , ( ) => {
830
843
it ( 'should destroy document' , ( ) => {
831
844
sinon . spy ( model . document , 'destroy' ) ;
You can’t perform that action at this time.
0 commit comments