Skip to content
Source
Sign inSign up
TanStack/showcase
A read-only demo of every feature
Every page of this repository is open, and nothing can change. Take a guided tour of what TanStack Source does.

feat: add clearDone to remove the done tasks #11

OpenAlemTuzlakwants to merge 1 commit intomain fromfeat/clear-doneopened

Showing 4 changed files with 16 additions and 2 deletions (loading 1).

x
0 of 4 viewed, 4 left
1 addition and 1 deletionsrc/index.tsModified
View file
@@ -1,2 +1,2 @@
-export { addTask, completeTask, openTasks, removeTask, type Task, type TaskList } from './tasks.ts'
+export { addTask, clearDone, completeTask, openTasks, removeTask, type Task, type TaskList } from './tasks.ts'
export { formatList, progress } from './format.ts'
9 additions and 0 deletionssrc/tasks.tsModified
View file
@@ -37,3 +37,12 @@
export function openTasks(list: TaskList): TaskList {
return list.filter((task) => !task.done).toSorted((a, b) => a.priority - b.priority)
+​
+/**
+ * Removes every done task from `list`. The open tasks keep their order and their ids.
+ *
+ * @example clearDone(completeTask(addTask([], 'Ship it'), 1)) // []
+ */
+export function clearDone(list: TaskList): TaskList {
+ return list.filter((task) => !task.done)
+}
6 additions and 1 deletiontest/tasks.test.tsModified
View file
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
-import { addTask, completeTask, formatList, openTasks, progress, removeTask } from '../src/index.ts'
+import { addTask, clearDone, completeTask, formatList, openTasks, progress, removeTask } from '../src/index.ts'
​
describe('tasks', () => {
it('gives each new task the next id', () => {
@@ -20,6 +20,11 @@