Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. import { Task } from '../models/task.model';
  2.  
  3. export class Board {
  4. private _tasks: Task[];
  5. private static _referenceCount: number = 0;
  6.  
  7. constructor() {
  8. this._tasks = [];
  9. Board._referenceCount++ ;
  10. }
  11.  
  12.  
  13. public get referenceCount(): number {
  14. return Board._referenceCount;
  15. }
  16.  
  17.  
  18. public get tasks(): Task[] {
  19. return this._tasks;
  20. }
  21.  
  22. public get taskCount(): number {
  23. return this._tasks.length;
  24. }
  25.  
  26. public add(task: Task): void {
  27. if (this._tasks.includes(task)) {
  28. throw new Error('You already have this task!');
  29. }
  30. this._tasks.push(task);
  31. }
  32.  
  33. public remove(task: Task): void {
  34. const index = this._tasks.indexOf(task);
  35. if (index > -1) {
  36. this._tasks.splice(index, 1);
  37. } else {
  38. throw new Error('There is no task in the list!');
  39. }
  40. }
  41.  
  42. toString() {
  43. if (this._tasks.length === 0) {
  44. return `
  45. ---Task Board---
  46.  
  47. Tasks:
  48.  
  49. No tasks at the moment.`;
  50. } else {
  51. return `
  52. ---Task Board---
  53.  
  54. Tasks:
  55. ${this._tasks.join(`--------`)}
  56. `}
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement