0147ff3efc7e8aaef27b7100505c01ad11f9acd1
[WebKit-https.git] / PerformanceTests / Speedometer / resources / todomvc / architecture-examples / emberjs / source / app / services / repo.js
1 import Ember from 'ember';
2 import * as localStorageMemory from './memory';
3
4 export default Ember.Service.extend({
5     lastId: 0,
6     data: null,
7     findAll() {
8         return this.get('data') ||
9             this.set('data', JSON.parse(localStorageMemory.getItem('todos') || '[]'));
10     },
11
12     add(attrs) {
13         let todo = Object.assign({ id: this.incrementProperty('lastId') }, attrs);
14         this.get('data').pushObject(todo);
15         this.persist();
16         return todo;
17     },
18
19     delete(todo) {
20         this.get('data').removeObject(todo);
21         this.persist();
22     },
23
24     persist() {
25         localStorageMemory.setItem('todos', JSON.stringify(this.get('data')));
26     }
27 });