Skip to content

Commit

Permalink
Merge pull request #502 from radiolips/bugfix/notify-fix
Browse files Browse the repository at this point in the history
Bugfix/notify fix - #411
  • Loading branch information
radiolips committed Aug 16, 2016
2 parents 1079cd4 + 34213e6 commit a04a247
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 33 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,9 @@ Changes

#### v0.2.6-dev (Development version)

- update requirements to the latest versions
- fix jQuery `size()`
- update requirements to the latest versions of jQuery and jquery-ui.
- fix jQuery `size()` ([#486](https://github.com/troolee/gridstack.js/issues/486)).
- update _notify to allow detach ([#411](https://github.com/troolee/gridstack.js/issues/411)).

#### v0.2.5 (2016-03-02)

Expand Down
17 changes: 9 additions & 8 deletions dist/gridstack.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,14 @@
};

GridStackEngine.prototype._notify = function() {
var args = Array.prototype.slice.call(arguments, 0);
args[0] = typeof args[0] === 'undefined' ? [] : [args[0]];
args[1] = typeof args[1] === 'undefined' ? true : args[1];
if (this._updateCounter) {
return;
}
var deletedNodes = Array.prototype.slice.call(arguments, 0);
deletedNodes = deletedNodes.concat(this.getDirtyNodes());
this.onchange(deletedNodes);
var deletedNodes = args[0].concat(this.getDirtyNodes());
this.onchange(deletedNodes, args[1]);
};

GridStackEngine.prototype.cleanNodes = function() {
Expand Down Expand Up @@ -345,9 +347,7 @@
node._id = null;
this.nodes = _.without(this.nodes, node);
this._packNodes();
if (detachNode) {
this._notify(node);
}
this._notify(node, detachNode);
};

GridStackEngine.prototype.canMoveNode = function(node, x, y, width, height) {
Expand Down Expand Up @@ -578,10 +578,11 @@

this._initStyles();

this.grid = new GridStackEngine(this.opts.width, function(nodes) {
this.grid = new GridStackEngine(this.opts.width, function(nodes, detachNode) {
detachNode = typeof detachNode === 'undefined' ? true : detachNode;
var maxHeight = 0;
_.each(nodes, function(n) {
if (n._id === null) {
if (detachNode && n._id === null) {
if (n.el) {
n.el.remove();
}
Expand Down
10 changes: 3 additions & 7 deletions dist/gridstack.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/gridstack.min.map

Large diffs are not rendered by default.

24 changes: 17 additions & 7 deletions spec/gridstack-engine-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,21 +176,31 @@ describe('gridstack engine', function() {
expect(spy.callback).toHaveBeenCalledWith([
engine.nodes[0],
engine.nodes[1]
]);
], true);
});

it('should by called with extra passed dirty nodes', function() {
var n1 = {idx: -1},
n2 = {idx: -2};
it('should by called with extra passed node to be removed', function() {
var n1 = {idx: -1};

engine._notify(n1, n2);
engine._notify(n1);

expect(spy.callback).toHaveBeenCalledWith([
n1,
n2,
engine.nodes[0],
engine.nodes[1]
]);
], true);
});

it('should by called with extra passed node to be removed and should maintain false parameter', function() {
var n1 = {idx: -1};

engine._notify(n1, false);

expect(spy.callback).toHaveBeenCalledWith([
n1,
engine.nodes[0],
engine.nodes[1]
], false);
});
});

Expand Down
17 changes: 9 additions & 8 deletions src/gridstack.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,14 @@
};

GridStackEngine.prototype._notify = function() {
var args = Array.prototype.slice.call(arguments, 0);
args[0] = typeof args[0] === 'undefined' ? [] : [args[0]];
args[1] = typeof args[1] === 'undefined' ? true : args[1];
if (this._updateCounter) {
return;
}
var deletedNodes = Array.prototype.slice.call(arguments, 0);
deletedNodes = deletedNodes.concat(this.getDirtyNodes());
this.onchange(deletedNodes);
var deletedNodes = args[0].concat(this.getDirtyNodes());
this.onchange(deletedNodes, args[1]);
};

GridStackEngine.prototype.cleanNodes = function() {
Expand Down Expand Up @@ -345,9 +347,7 @@
node._id = null;
this.nodes = _.without(this.nodes, node);
this._packNodes();
if (detachNode) {
this._notify(node);
}
this._notify(node, detachNode);
};

GridStackEngine.prototype.canMoveNode = function(node, x, y, width, height) {
Expand Down Expand Up @@ -578,10 +578,11 @@

this._initStyles();

this.grid = new GridStackEngine(this.opts.width, function(nodes) {
this.grid = new GridStackEngine(this.opts.width, function(nodes, detachNode) {
detachNode = typeof detachNode === 'undefined' ? true : detachNode;
var maxHeight = 0;
_.each(nodes, function(n) {
if (n._id === null) {
if (detachNode && n._id === null) {
if (n.el) {
n.el.remove();
}
Expand Down

0 comments on commit a04a247

Please sign in to comment.