Skip to content

Commit 7bbf637

Browse files
Create a store on the database for posts, then save all the posts to that store
1 parent 43cd766 commit 7bbf637

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

public/js/main/IndexController.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ function openDatabase() {
1414
// that uses 'id' as its key
1515
// and has an index called 'by-date', which is sorted
1616
// by the 'time' property
17+
return = idb.open('wittr', 1, function(upgradeDb) {
18+
var wittrs = upgradeDb.createObjectStore('wittrs', { keyPath: 'id' });
19+
wittrs.createIndex('by-date', 'time');
20+
});
1721
}
1822

1923
export default function IndexController(container) {
@@ -135,7 +139,13 @@ IndexController.prototype._onSocketMessage = function(data) {
135139

136140
// TODO: put each message into the 'wittrs'
137141
// object store.
142+
var tx = db.transaction('wittrs', 'readwrite');
143+
var wittrsStore = tx.objectStore('wittrs');
144+
145+
messages.forEach(function(message) {
146+
wittrsStore.put(message);
147+
});
138148
});
139149

140150
this._postsView.addPosts(messages);
141-
};
151+
};

0 commit comments

Comments
 (0)