8
0
Просмотр исходного кода

Improved Adapter documentation.

Szymon Kupś 8 лет назад
Родитель
Сommit
8ff83bf639
1 измененных файлов с 46 добавлено и 14 удалено
  1. 46 14
      packages/ckeditor5-upload/src/filerepository.js

+ 46 - 14
packages/ckeditor5-upload/src/filerepository.js

@@ -49,15 +49,7 @@ export default class FileRepository extends Plugin {
 		 * {@link module:upload/filerepository~FileLoader FileLoader} instance will be passed to that function.
 		 *
 		 *	fileRepository.createAdapter = function( loader ) {
-		 *		return {
-		 *			upload: function() {
-		 *				return doSomeUpload( loader.file );
-		 *			},
-		 *
-		 *			abort: function() {
-		 *				abortUpload();
-		 *			}
-		 *		};
+		 *		return new ServerAdapter();
 		 *	};
 		 *
 		 * @abstract
@@ -400,21 +392,61 @@ class FileLoader {
 mix( FileLoader, ObservableMixin );
 
 /**
- * Adapter abstract class used by FileRepository to handle file upload.
+ * Adapter interface used by FileRepository to handle file upload. Adapter is a bridge between the editor and server that
+ * handles file uploads. It should contain logic necessary to initiate upload process and monitor its progress.
+ *
+ * It should implement two methods:
+ * * {@link module:upload/filerepository~Adapter#upload upload()},
+ * * {@link module:upload/filerepository~Adapter#abort abort()}.
+ *
+ * Example adapter implementation:
+ *
+ *	class Adapter {
+ *		constructor( loader ) {
+ *			// Save Loader instance to update upload progress.
+ *			this.loader = loader;
+ *		}
+ *
+ *		upload() {
+ *			// Update loader's progress.
+ *			server.onUploadProgress( data => {
+ *				loader.uploadTotal = data.total;
+ *				loader.uploaded = data.uploaded;
+ *			} ):
+ *
+ *			// Return promise that will be resolved when file is uploaded.
+ *			return server.upload( loader.file );
+ *		}
+ *
+ *		abort() {
+ *			// Reject promise returned from upload() method.
+ *			server.abortUpload();
+ *		}
+ *	}
  *
  * @interface Adapter
  */
 
 /**
  * Executes the upload process.
+ * This method should return a promise that will resolve when data will be uploaded to server. Promise should be
+ * resolved with an object containing information about uploaded file:
+ *
+ *	{
+ *		original: 'http://server/orginal-size.image.png'
+ *	}
  *
- * @method #upload
+ * Take a look at {@link module:upload/filerepository~Adapter example Adapter implementation}.
+ *
+ * @method module:upload/filerepository~Adapter#upload
  * @returns {Promise} Promise that should be resolved when data is uploaded.
  */
 
 /**
- * Aborts the upload proccess.
- * After aborting it should reject promise returned from {@link #upload} method with "aborted" string.
+ * Aborts the upload process.
+ * After aborting it should reject promise returned from {@link #upload upload()} method with "aborted" string.
+ *
+ * Take a look at {@link module:upload/filerepository~Adapter example Adapter implementation}.
  *
- * @method #abort
+ * @method module:upload/filerepository~Adapter#abort
  */