|
@@ -64,6 +64,8 @@ export default class Autosave extends Plugin {
|
|
|
constructor( editor ) {
|
|
constructor( editor ) {
|
|
|
super( editor );
|
|
super( editor );
|
|
|
|
|
|
|
|
|
|
+ const config = editor.config.get( 'autosave' ) || {};
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* The adapter is an object with a `save()` method. That method will be called whenever
|
|
* The adapter is an object with a `save()` method. That method will be called whenever
|
|
|
* the data changes. It might be called some time after the change,
|
|
* the data changes. It might be called some time after the change,
|
|
@@ -85,13 +87,22 @@ export default class Autosave extends Plugin {
|
|
|
*/
|
|
*/
|
|
|
this.set( 'state', 'synchronized' );
|
|
this.set( 'state', 'synchronized' );
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * A minimum amount of time that needs to pass after the last action.
|
|
|
|
|
+ * After that time the provided save callbacks are being called.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @protected
|
|
|
|
|
+ * @type {Number}
|
|
|
|
|
+ */
|
|
|
|
|
+ this._waitingTime = config.waitingTime || 2000;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Throttled save method.
|
|
* Throttled save method.
|
|
|
*
|
|
*
|
|
|
* @protected
|
|
* @protected
|
|
|
* @type {Function}
|
|
* @type {Function}
|
|
|
*/
|
|
*/
|
|
|
- this._debouncedSave = debounce( this._save.bind( this ), 2000 );
|
|
|
|
|
|
|
+ this._debouncedSave = debounce( this._save.bind( this ), this._debounceTime );
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Last document version.
|
|
* Last document version.
|
|
@@ -122,7 +133,7 @@ export default class Autosave extends Plugin {
|
|
|
* @private
|
|
* @private
|
|
|
* @type {Object}
|
|
* @type {Object}
|
|
|
*/
|
|
*/
|
|
|
- this._config = editor.config.get( 'autosave' ) || {};
|
|
|
|
|
|
|
+ this._config = config;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Editor's pending actions manager.
|
|
* Editor's pending actions manager.
|
|
@@ -328,3 +339,22 @@ mix( Autosave, ObservableMixin );
|
|
|
* @param {module:core/editor/editor~Editor} editor The editor instance.
|
|
* @param {module:core/editor/editor~Editor} editor The editor instance.
|
|
|
* @returns {Promise.<*>}
|
|
* @returns {Promise.<*>}
|
|
|
*/
|
|
*/
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * The minimum amount of time that need to pass after last action to call the provided callback.
|
|
|
|
|
+ *
|
|
|
|
|
+ * ClassicEditor
|
|
|
|
|
+ * .create( editorElement, {
|
|
|
|
|
+ * autosave: {
|
|
|
|
|
+ * save( editor ) {
|
|
|
|
|
+ * return saveData( editor.getData() );
|
|
|
|
|
+ * },
|
|
|
|
|
+ * waitingTime: 1000
|
|
|
|
|
+ * }
|
|
|
|
|
+ * } );
|
|
|
|
|
+ * .then( ... )
|
|
|
|
|
+ * .catch( ... );
|
|
|
|
|
+ *
|
|
|
|
|
+ * @property module:autosave/autosave~AutosaveConfig#waitingTime
|
|
|
|
|
+ * @type {Number}
|
|
|
|
|
+ */
|