Procházet zdrojové kódy

Changed property name: provider to adapter.

Maciej Bukowski před 7 roky
rodič
revize
f82bf914ba

+ 17 - 11
packages/ckeditor5-autosave/src/autosave.js

@@ -17,7 +17,7 @@ import throttle from './throttle';
 /**
  * Autosave plugin provides an easy-to-use API to save the editor's content.
  * It watches {@link module:engine/model/document~Document#event:change:data change:data}
- * and `Window:beforeunload` events and calls the {@link module:autosave/autosave~SaveProvider#save} method.
+ * and `Window:beforeunload` events and calls the {@link module:autosave/autosave~Adapter#save} method.
  *
  * 		ClassicEditor
  *			.create( document.querySelector( '#editor' ), {
@@ -29,7 +29,7 @@ import throttle from './throttle';
  *			} )
  *			.then( editor => {
  *				const autosave = editor.plugins.get( Autosave );
- *				autosave.provider = {
+ *				autosave.adapter = {
  *					save() {
  *						const data = editor.getData();
  *
@@ -61,13 +61,13 @@ export default class Autosave extends Plugin {
 		super( editor );
 
 		/**
-		 * Provider is an object with the `save()` method. That method will be called whenever
+		 * The adapter is an object with the `save()` method. That method will be called whenever
 		 * the model's data changes. It might be called some time after the change,
 		 * since the event is throttled for performance reasons.
 		 *
-		 * @type {module:autosave/autosave~SaveProvider}
+		 * @type {module:autosave/autosave~Adapter}
 		 */
-		this.provider = undefined;
+		this.adapter = undefined;
 
 		/**
 		 * Throttled save method.
@@ -86,6 +86,8 @@ export default class Autosave extends Plugin {
 		this._lastDocumentVersion = editor.model.document.version;
 
 		/**
+		 * DOM emitter.
+		 *
 		 * @private
 		 * @type {DomEmitterMixin}
 		 */
@@ -169,8 +171,8 @@ export default class Autosave extends Plugin {
 	}
 
 	/**
-	 * If the provider is set and new document version exists,
-	 * `_save()` method creates a pending action and calls `provider.save()` method.
+	 * If the adapter is set and new document version exists,
+	 * `_save()` method creates a pending action and calls `adapter.save()` method.
 	 * It waits for the result and then removes the created pending action.
 	 *
 	 * @private
@@ -180,7 +182,7 @@ export default class Autosave extends Plugin {
 
 		// Marker's change may not produce an operation, so the document's version
 		// can be the same after that change.
-		if ( !this.provider || version < this._lastDocumentVersion ) {
+		if ( !this.adapter || version < this._lastDocumentVersion ) {
 			this._decrementCounter();
 
 			return;
@@ -188,7 +190,7 @@ export default class Autosave extends Plugin {
 
 		this._lastDocumentVersion = version;
 
-		Promise.resolve( this.provider.save() )
+		Promise.resolve( this.adapter.save() )
 			.then( () => {
 				this._decrementCounter();
 			} );
@@ -224,12 +226,16 @@ export default class Autosave extends Plugin {
 }
 
 /**
- * @interface module:autosave/autosave~SaveProvider
+ * An interface that requires the `save()` method.
+ *
+ * Used by {module:autosave/autosave~Autosave#adapter}
+ *
+ * @interface module:autosave/autosave~Adapter
  */
 
 /**
  * Method that will be called when the data model changes. It should return a promise (e.g. in case of saving content to the database),
- * so the `Autosave` plugin will wait for that action before removing it from the pending actions.
+ * so the `Autosave` plugin will wait for that action before removing it from pending actions.
  *
  * @method #save
  * @returns {Promise.<*>|undefined}

+ 26 - 26
packages/ckeditor5-autosave/tests/autosave.js

@@ -48,11 +48,11 @@ describe( 'Autosave', () => {
 	} );
 
 	describe( 'initialization', () => {
-		it( 'should initialize provider with an undefined value', () => {
-			expect( autosave.provider ).to.be.undefined;
+		it( 'should initialize adapter with an undefined value', () => {
+			expect( autosave.adapter ).to.be.undefined;
 		} );
 
-		it( 'should allow plugin to work without any defined provider', () => {
+		it( 'should allow plugin to work without any defined adapter', () => {
 			editor.model.change( writer => {
 				writer.setSelection( ModelRange.createIn( editor.model.document.getRoot().getChild( 0 ) ) );
 				editor.model.insertContent( new ModelText( 'foo' ), editor.model.document.selection );
@@ -63,8 +63,8 @@ describe( 'Autosave', () => {
 	} );
 
 	describe( 'autosaving', () => {
-		it( 'should run provider\'s save method when the editor\'s change event is fired', () => {
-			autosave.provider = {
+		it( 'should run adapter\'s save method when the editor\'s change event is fired', () => {
+			autosave.adapter = {
 				save: sinon.spy()
 			};
 
@@ -76,14 +76,14 @@ describe( 'Autosave', () => {
 			// Go to the next cycle to because synchronization of CS documentVersion is async.
 			autosave._flush();
 
-			sinon.assert.calledOnce( autosave.provider.save );
+			sinon.assert.calledOnce( autosave.adapter.save );
 		} );
 
 		it( 'should throttle editor\'s change event', () => {
 			const spy = sinon.spy();
 			const savedStates = [];
 
-			autosave.provider = {
+			autosave.adapter = {
 				save() {
 					spy();
 
@@ -125,7 +125,7 @@ describe( 'Autosave', () => {
 			const serverActionStub = sinon.stub();
 			serverActionStub.onCall( 0 ).resolves( wait( 500 ).then( serverActionSpy ) );
 
-			autosave.provider = {
+			autosave.adapter = {
 				save: serverActionStub
 			};
 
@@ -149,7 +149,7 @@ describe( 'Autosave', () => {
 			const serverActionSpy = sinon.spy();
 			const pendingActions = editor.plugins.get( PendingActions );
 
-			autosave.provider = {
+			autosave.adapter = {
 				save: serverActionSpy
 			};
 
@@ -179,7 +179,7 @@ describe( 'Autosave', () => {
 			serverActionStub.onCall( 0 ).resolves( wait( 500 ).then( serverActionSpy ) );
 			serverActionStub.onCall( 1 ).resolves( wait( 1000 ).then( serverActionSpy ) );
 
-			autosave.provider = {
+			autosave.adapter = {
 				save: serverActionStub
 			};
 
@@ -218,7 +218,7 @@ describe( 'Autosave', () => {
 			const serverActionSpy = sinon.spy();
 			const pendingActions = editor.plugins.get( PendingActions );
 
-			autosave.provider = {
+			autosave.adapter = {
 				save: serverActionSpy
 			};
 
@@ -254,7 +254,7 @@ describe( 'Autosave', () => {
 		} );
 
 		it( 'should filter out changes in the selection', () => {
-			autosave.provider = {
+			autosave.adapter = {
 				save: sandbox.spy()
 			};
 
@@ -263,11 +263,11 @@ describe( 'Autosave', () => {
 			} );
 
 			autosave._flush();
-			sinon.assert.notCalled( autosave.provider.save );
+			sinon.assert.notCalled( autosave.adapter.save );
 		} );
 
 		it( 'should filter out markers that does not affect the data model', () => {
-			autosave.provider = {
+			autosave.adapter = {
 				save: sandbox.spy()
 			};
 
@@ -286,11 +286,11 @@ describe( 'Autosave', () => {
 
 			autosave._flush();
 
-			sinon.assert.notCalled( autosave.provider.save );
+			sinon.assert.notCalled( autosave.adapter.save );
 		} );
 
 		it( 'should filter out markers that does not affect the data model #2', () => {
-			autosave.provider = {
+			autosave.adapter = {
 				save: sandbox.spy()
 			};
 
@@ -309,11 +309,11 @@ describe( 'Autosave', () => {
 
 			autosave._flush();
 
-			sinon.assert.notCalled( autosave.provider.save );
+			sinon.assert.notCalled( autosave.adapter.save );
 		} );
 
 		it( 'should call the save method when some marker affects the data model', () => {
-			autosave.provider = {
+			autosave.adapter = {
 				save: sandbox.spy()
 			};
 
@@ -332,11 +332,11 @@ describe( 'Autosave', () => {
 
 			autosave._flush();
 
-			sinon.assert.calledTwice( autosave.provider.save );
+			sinon.assert.calledTwice( autosave.adapter.save );
 		} );
 
 		it( 'should call the save method when some marker affects the data model #2', () => {
-			autosave.provider = {
+			autosave.adapter = {
 				save: sandbox.spy()
 			};
 
@@ -348,7 +348,7 @@ describe( 'Autosave', () => {
 			} );
 
 			autosave._flush();
-			sinon.assert.calledOnce( autosave.provider.save );
+			sinon.assert.calledOnce( autosave.adapter.save );
 
 			editor.model.change( writer => {
 				writer.updateMarker( 'name', { range: range2 } );
@@ -356,11 +356,11 @@ describe( 'Autosave', () => {
 
 			autosave._flush();
 
-			sinon.assert.calledTwice( autosave.provider.save );
+			sinon.assert.calledTwice( autosave.adapter.save );
 		} );
 
 		it( 'should call the save method when some marker affects the data model #3', () => {
-			autosave.provider = {
+			autosave.adapter = {
 				save: sandbox.spy()
 			};
 
@@ -372,14 +372,14 @@ describe( 'Autosave', () => {
 			} );
 
 			autosave._flush();
-			sinon.assert.calledOnce( autosave.provider.save );
+			sinon.assert.calledOnce( autosave.adapter.save );
 		} );
 
 		it( 'should flush remaining calls after editor\'s destroy', () => {
 			const spy = sandbox.spy();
 			const savedStates = [];
 
-			autosave.provider = {
+			autosave.adapter = {
 				save() {
 					spy();
 
@@ -413,7 +413,7 @@ describe( 'Autosave', () => {
 			const serverActionStub = sinon.stub();
 			serverActionStub.onCall( 0 ).resolves( wait( 500 ).then( serverActionSpy ) );
 
-			autosave.provider = {
+			autosave.adapter = {
 				save: serverActionStub
 			};
 

+ 1 - 1
packages/ckeditor5-autosave/tests/manual/autosave.js

@@ -25,7 +25,7 @@ ClassicEditor
 		destroyButton.addEventListener( 'click', () => editor.destroy() );
 
 		const autosave = editor.plugins.get( Autosave );
-		autosave.provider = {
+		autosave.adapter = {
 			save() {
 				const data = editor.getData();