Skip to content

Commit

Permalink
Merge pull request #67 from bikingbadger/66-timer-issue
Browse files Browse the repository at this point in the history
Timer issue
  • Loading branch information
bikingbadger authored Jun 2, 2020
2 parents 5c28012 + 62e7fd6 commit 1874a8f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 24 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,11 @@ By clicking on the task this will set it to the current task in the timer. This

## Completing task

By clicking on the task in the current task will move it to the completed tasks and remove from the Todo list
By clicking on the task in the current task will move it to the completed tasks and remove from the Todo list

## Development

```
npm install
npm run dev
```
46 changes: 23 additions & 23 deletions src/modules/timer/controller.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,30 @@ const TimerController = {
*/
startTimer: function () {
this.model.start();
// Use a faster timeout for local testing
const timeout =
window.location.hostname === 'localhost' ||
window.location.hostname === '127.0.0.1'
? 1
: 1000;
// // Use a faster timeout for local testing
// const timeout =
// window.location.hostname === 'localhost' ||
// window.location.hostname === '127.0.0.1'
// ? 1
// : 1000;
// Only start a new timer if one is not already running
if (!this.countDown === null) return;
this.countDown = window.setInterval(() => {
//Make sure the timer is running and not paused
if (this.model.running) {
// Check if the timer has ended, if it has determine the next course of action
if (this.model.currentTime <= 0) {
this.model.stop();
this.model.next();
} else {
/**
* Decrease the timer
*/
this.model.decrease();
}
}
// renderTimer();
}, timeout);
// if (!this.countDown === null) return;
// this.countDown = window.setInterval(() => {
// //Make sure the timer is running and not paused
// if (this.model.running) {
// // Check if the timer has ended, if it has determine the next course of action
// if (this.model.currentTime <= 0) {
// this.model.stop();
// this.model.next();
// } else {
// /**
// * Decrease the timer
// */
// this.model.decrease();
// }
// }
// // renderTimer();
// }, timeout);
},
/**
* Pause the timer
Expand Down
25 changes: 25 additions & 0 deletions src/modules/timer/model.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,38 @@ const TimerModel = {
pompoms: 0,
pubSub: null,
subject: 'timer',
countDown: null,
/**
* Load the object with all its default settings
*/
load: function (PubSub) {
// console.log(PubSub);
this.pubSub = PubSub;
this.publish();

// Use a faster timeout for local testing
const timeout =
window.location.hostname === 'localhost' ||
window.location.hostname === '127.0.0.1'
? 10
: 1000;

// create the timer once
this.countDown = window.setInterval(() => {
//Make sure the timer is running and not paused
if (this.running) {
// Check if the timer has ended, if it has determine the next course of action
if (this.currentTime <= 0) {
this.stop();
this.next();
} else {
/**
* Decrease the timer
*/
this.decrease();
}
}
}, timeout);
},
publish: function () {
this.pubSub.publish(this);
Expand Down

0 comments on commit 1874a8f

Please sign in to comment.