Skip to content

Commit

Permalink
Update default add and remove listeners in UndoManager
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Jan 22, 2018
1 parent a63fe5a commit 795d15f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
22 changes: 22 additions & 0 deletions src/undo_manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,28 @@ module.exports = () => {
this.em = em;
um = new UndoManager({ track: true, register: [] });
um.changeUndoType('change', { condition: false });
um.changeUndoType('add', {
on(model, collection, options = {}) {
if (options.avoidStore) return;
return {
object: collection,
before: undefined,
after: model,
options: { ...options }
};
}
});
um.changeUndoType('remove', {
on(model, collection, options = {}) {
if (options.avoidStore) return;
return {
object: collection,
before: model,
after: undefined,
options: { ...options }
};
}
});
const customUndoType = {
on(object, value, opt = {}) {
!beforeCache && (beforeCache = object.previousAttributes());
Expand Down
12 changes: 7 additions & 5 deletions src/utils/Sorter.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,14 @@ module.exports = Backbone.View.extend({
if (dropContent && em) {
if (!dropModel) {
let comps = em.get('DomComponents').getComponents();
let tempModel = comps.add(dropContent, {
const opts = {
avoidStore: 1,
avoidChildren: 1,
avoidUpdateStyle: 1,
temporary: 1
});
dropModel = comps.remove(tempModel, { temporary: 1 });
};
let tempModel = comps.add(dropContent, opts);
dropModel = comps.remove(tempModel, opts);
this.dropModel = dropModel instanceof Array ? dropModel[0] : dropModel;
}
return dropModel;
Expand Down Expand Up @@ -972,7 +974,7 @@ module.exports = Backbone.View.extend({
var opts = { at: index, noIncrement: 1 };

if (!dropContent) {
modelTemp = targetCollection.add({}, opts);
modelTemp = targetCollection.add({}, { ...opts, avoidStore: 1 });

if (model) {
modelToDrop = model.collection.remove(model);
Expand All @@ -986,7 +988,7 @@ module.exports = Backbone.View.extend({
created = targetCollection.add(modelToDrop, opts);

if (!dropContent) {
targetCollection.remove(modelTemp);
targetCollection.remove(modelTemp, { avoidStore: 1 });
} else {
this.dropContent = null;
}
Expand Down

0 comments on commit 795d15f

Please sign in to comment.