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

Improved code readability #4

Merged
merged 4 commits into from
Mar 22, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/moveTo.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const MoveTo = (() => {
tolerance: 0,
duration: 800,
easing: 'easeOutQuart',
callback: function() {},
Copy link
Owner

Choose a reason for hiding this comment

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

This is an eslint rule called the comma-dangle. This should not be erased.

callback: function() {}
};

/**
Expand All @@ -19,10 +19,10 @@ const MoveTo = (() => {
* @param {number} d - duration
* @return {number} - calculated value
*/
function easeOutQuart(t, b, c, d) {
t /= d;
t--;
return -c * (t * t * t * t - 1) + b;
function easeOutQuart(currentTime, startValue, change, duration) {
Copy link
Owner

Choose a reason for hiding this comment

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

It is not necessary, the parameters are already explained above and Easing equations is usually known in this way.

Copy link
Contributor

Choose a reason for hiding this comment

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

JSDoc need to update, if these changes will take, but really got better, I would have left.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree.

currentTime /= duration;
currentTime--;
return -change * (currentTime * currentTime * currentTime * currentTime - 1) + startValue;
}

/**
Expand Down Expand Up @@ -121,7 +121,7 @@ const MoveTo = (() => {
* @param {object} options Custom options
*/
MoveTo.prototype.move = function(target, options = {}) {
if (target !== 0 && !target) {
Copy link
Owner

Choose a reason for hiding this comment

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

target !== 0 should not be deleted here, otherwise if target is 0 the scroll animation will not work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

0 is falsy in JavaScript. So you need not check that if you are checking for !target.

All these evaluate to false.
if (false), if (null), if (undefined), if (0), if (NaN), if (''), if (""), if (document.all) [1]

Copy link
Owner

@hsnaydd hsnaydd Mar 22, 2017

Choose a reason for hiding this comment

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

Yes as you said 0 is falsy. If we do it the way you do, move function will return without work

// when target 0 
if (!0) {
  // will return 
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I get it now!

if (!target) {
return;
}

Expand All @@ -139,15 +139,15 @@ const MoveTo = (() => {
let currentPageYOffset = window.pageYOffset;

if (!startTime) {
// To starts time from 1, we subtracted -1 from current time
// To starts time from 1, we subtracted 1 from current time
// If time starts from 1 The first loop will not do anything,
// because easing value will be zero
startTime = currentTime - 1;
}

const timeElapsed = currentTime - startTime;

if (lastPageYOffset !== 0) {
if (lastPageYOffset) {
if (
(lastPageYOffset === currentPageYOffset) ||
(change > 0 && lastPageYOffset > currentPageYOffset) ||
Expand Down