8
0

controller.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. CKEDITOR.define( [ 'collection', 'model' ], function( Collection, Model ) {
  7. class Controller extends Model {
  8. /**
  9. * @constructor
  10. */
  11. constructor( model, view ) {
  12. super();
  13. this.model = model;
  14. this.view = view;
  15. this.controllers = new Collection();
  16. }
  17. /**
  18. * @param
  19. * @returns
  20. */
  21. init() {
  22. // Note: Because this.view.init() can by sync as well as async,
  23. // this method is not returning this.view.init() directly.
  24. return Promise.resolve()
  25. .then( () => {
  26. return this.view.init();
  27. } );
  28. }
  29. /**
  30. * @param
  31. * @returns
  32. */
  33. append( controller, regionName ) {
  34. this.controllers.add( controller );
  35. // Note: Because controller.init() can by sync as well as async,
  36. // it is wrapped in promise.
  37. return Promise.resolve()
  38. .then( () => {
  39. return controller.init();
  40. } )
  41. .then( () => {
  42. this.view.append( controller.view, regionName );
  43. } )
  44. .then( () => {
  45. return controller;
  46. } );
  47. }
  48. /**
  49. * @param
  50. * @returns
  51. */
  52. destroy() {
  53. }
  54. }
  55. return Controller;
  56. } );