summaryrefslogtreecommitdiffstats
path: root/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/angular/src/app/todo-data.service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/angular/src/app/todo-data.service.ts')
-rw-r--r--third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/angular/src/app/todo-data.service.ts63
1 files changed, 63 insertions, 0 deletions
diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/angular/src/app/todo-data.service.ts b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/angular/src/app/todo-data.service.ts
new file mode 100644
index 0000000000..509e37d5d4
--- /dev/null
+++ b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/angular/src/app/todo-data.service.ts
@@ -0,0 +1,63 @@
+import {Injectable} from '@angular/core';
+import {Todo} from './todo';
+
+@Injectable()
+export class TodoDataService {
+
+ // Placeholder for last id so we can simulate
+ // automatic incrementing of id's
+ lastId: number = 0;
+
+ // Placeholder for todo's
+ todos: Todo[] = [];
+
+ constructor() {
+ }
+
+ // Simulate POST /todos
+ addTodo(todo: Todo): TodoDataService {
+ if (!todo.id) {
+ todo.id = ++this.lastId;
+ }
+ this.todos.push(todo);
+ return this;
+ }
+
+ // Simulate DELETE /todos/:id
+ deleteTodoById(id: number): TodoDataService {
+ this.todos = this.todos
+ .filter(todo => todo.id !== id);
+ return this;
+ }
+
+ // Simulate PUT /todos/:id
+ updateTodoById(id: number, values: Object = {}): Todo {
+ let todo = this.getTodoById(id);
+ if (!todo) {
+ return null;
+ }
+ Object.assign(todo, values);
+ return todo;
+ }
+
+ // Simulate GET /todos
+ getAllTodos(): Todo[] {
+ return this.todos;
+ }
+
+ // Simulate GET /todos/:id
+ getTodoById(id: number): Todo {
+ return this.todos
+ .filter(todo => todo.id === id)
+ .pop();
+ }
+
+ // Toggle todo complete
+ toggleTodoComplete(todo: Todo){
+ let updatedTodo = this.updateTodoById(todo.id, {
+ complete: !todo.complete
+ });
+ return updatedTodo;
+ }
+
+} \ No newline at end of file