Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated default values handling to one liner #129

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 7 additions & 22 deletions engine/flowy.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
var flowy = function(canvas, grab, release, snapping, rearrange, spacing_x, spacing_y) {
if (!grab) {
grab = function() {};
}
if (!release) {
release = function() {};
}
if (!snapping) {
snapping = function() {
return true;
}
}
if (!rearrange) {
rearrange = function() {
return false;
}
}
if (!spacing_x) {
spacing_x = 20;
}
if (!spacing_y) {
spacing_y = 80;
}
grab = grab || function() {};
release = release || function() {};
snapping = snapping || function () { true; }
rearrange = rearrange || function () { false; }
spacing_x = typeof spacing_x == undefined ? 20 : spacing_x;
spacing_y = typeof spacing_y == undefined ? 20 : spacing_y;
Comment on lines +2 to +7
Copy link

@Jhoubert Jhoubert Feb 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You code is breaking the normal behavior since is expecting a value, you're missing it, this is a working one-liner.

Suggested change
grab = grab || function() {};
release = release || function() {};
snapping = snapping || function () { true; }
rearrange = rearrange || function () { false; }
spacing_x = typeof spacing_x == undefined ? 20 : spacing_x;
spacing_y = typeof spacing_y == undefined ? 20 : spacing_y;
grab = grab || function() {};
release = release || function() {};
snapping = snapping || function () {return true; }
rearrange = rearrange || function () { return false; }
spacing_x = !spacing_x ? 20 : spacing_x;
spacing_y = !spacing_y ? 80: spacing_y;


if (!Element.prototype.matches) {
Element.prototype.matches = Element.prototype.msMatchesSelector ||
Element.prototype.webkitMatchesSelector;
Expand Down