operationfactory.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module engine/model/operation/operationfactory
  7. */
  8. import AttributeOperation from '../operation/attributeoperation';
  9. import InsertOperation from '../operation/insertoperation';
  10. import MoveOperation from '../operation/moveoperation';
  11. import NoOperation from '../operation/nooperation';
  12. import Operation from '../operation/operation';
  13. import ReinsertOperation from '../operation/reinsertoperation';
  14. import RemoveOperation from '../operation/removeoperation';
  15. import RenameOperation from '../operation/renameoperation';
  16. import RootAttributeOperation from '../operation/rootattributeoperation';
  17. const operations = {};
  18. operations[ AttributeOperation.className ] = AttributeOperation;
  19. operations[ InsertOperation.className ] = InsertOperation;
  20. operations[ MoveOperation.className ] = MoveOperation;
  21. operations[ NoOperation.className ] = NoOperation;
  22. operations[ Operation.className ] = Operation;
  23. operations[ ReinsertOperation.className ] = ReinsertOperation;
  24. operations[ RemoveOperation.className ] = RemoveOperation;
  25. operations[ RenameOperation.className ] = RenameOperation;
  26. operations[ RootAttributeOperation.className ] = RootAttributeOperation;
  27. /**
  28. * A factory class for creating operations.
  29. *
  30. * @abstract
  31. */
  32. export default class OperationFactory {
  33. /**
  34. * Creates concrete `Operation` object from deserilized object, i.e. from parsed JSON string.
  35. *
  36. * @param {Object} json Deserialized JSON object.
  37. * @param {module:engine/model/document~Document} document Document on which this operation will be applied.
  38. * @returns {module:engine/model/operation/operation~Operation}
  39. */
  40. static fromJSON( json, document ) {
  41. return operations[ json.__className ].fromJSON( json, document );
  42. }
  43. }