From 225c54703a227f6bb5c6cda365a4ce2207d04837 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Sat, 9 Mar 2019 23:58:08 +0100 Subject: [PATCH] Add `update` event to generaly listen any change to the template --- src/editor/index.js | 5 +++-- src/editor/model/Editor.js | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/editor/index.js b/src/editor/index.js index 7793d766b..b3c2060bb 100644 --- a/src/editor/index.js +++ b/src/editor/index.js @@ -88,10 +88,11 @@ * * `stop:{commandName}:before` - Triggered before the command is called to stop * * `abort:{commandName}` - Triggered when the command execution is aborted (`editor.on(`run:preview:before`, opts => opts.abort = 1);`) * ### General - * * `canvasScroll` - Triggered when the canvas is scrolle + * * `canvasScroll` - Canvas is scrolled + * * `update` - The structure of the template is updated (its HTML/CSS) * * `undo` - Undo executed * * `redo` - Redo executed - * * `load` - When the editor is loaded + * * `load` - Editor is loaded * * @module Editor */ diff --git a/src/editor/model/Editor.js b/src/editor/model/Editor.js index 46ac2dcba..2d7d26323 100644 --- a/src/editor/model/Editor.js +++ b/src/editor/model/Editor.js @@ -34,6 +34,7 @@ const deps = [ const Backbone = require('backbone'); const { Collection } = Backbone; let timedInterval; +let updateItr; require('utils/extender')({ Backbone: Backbone, @@ -156,6 +157,8 @@ module.exports = Backbone.Model.extend({ updateChanges() { const stm = this.get('StorageManager'); const changes = this.get('changesCount'); + updateItr && clearTimeout(updateItr); + updateItr = setTimeout(() => this.trigger('update')); if (this.config.noticeOnUnload) { window.onbeforeunload = changes ? e => 1 : null;