[PWA] 16. Clean IDB
When we save items to IndexDB, we need to think about clean the items or keep those in a short list.
IndexController.prototype._onSocketMessage = function(data) {
var messages = JSON.parse(data);
this._dbPromise.then(function(db) {
if (!db) return;
var tx = db.transaction('wittrs', 'readwrite');
var store = tx.objectStore('wittrs');
messages.forEach(function(message) {
store.put(message);
});
// TODO: keep the newest 30 entries in 'wittrs',
// but delete the rest.
//
// Hint: you can use .openCursor(null, 'prev') to
// open a cursor that goes through an index/store
// backwards.
store.index('by-date').openCursor(null, 'prev')
.then((cursor)=>{
return cursor.advance(); // only 30 itmes are kept
}).then(function deleteCursor(cursor){
if(!cursor){
return;
}else{
cursor.delete();
return cursor.continue().then(deleteCursor);
}
})
});
this._postsView.addPosts(messages);
};
[PWA] 16. Clean IDB的更多相关文章
- [PWA] 18. Clean the photo cache
We cannot let photo always keep caching new data without clean the old data. If message is not displ ...
- Hexo博客美化之蝴蝶(butterfly)主题魔改
Hexo是轻量级的极客博客,因为它简便,轻巧,扩展性强,搭建部署方便深受广大人们的喜爱.各种琳琅满路的Hexo主题也是被各种大佬开发出来,十分钦佩,向大佬仰望,大声称赞:流批!!! 我在翻看各种主 ...
- ubuntu6.04安装
一.在windows操作系统下准备ubuntu系统的安装盘 1. 下载ubuntu的ISO文件 这一步相对简单,网络上面有很多的链接下载.这里贴一个ubuntu的官方网站链接,可以下载到ubuntu ...
- javascript:base.superclass.constructor.call(this,config)
javascript中类的继承机制如下,有一个baseClass的类,然后为其定义两个方法,someMethod()和overwriteMethod() 1 var BaseClass = funct ...
- i.mx53开发的一些问题
i.mx53开发的一些问题 转载于此:http://blog.csdn.net/shell_albert/article/details/8242288 原来i.mx53上4GB的Nand Fla ...
- 对freescale的mfgtool的ucl2.xml的理解
转载于此:http://blog.csdn.net/bugouyonggan/article/details/8664898 对于Freescale MFG编程工具控制文件ucl2.xml的分析 为了 ...
- 将linux和uboot集成到Android编译框架中
span::selection, .CodeMirror-line > span > span::selection { background: #d7d4f0; }.CodeMirror ...
- Spring框架之jms源码完全解析
Spring框架之jms源码完全解析 我们在前两篇文章中介绍了Spring两大核心IOC(Inversion of Control控制反转)和AOP(Aspect Oriented Programmi ...
- [PWA] 15. Using The IDB Cache And Display Entries
We want to use IDB to store the wittr messages. The logic is when the page start: service worker wil ...
随机推荐
- 虚拟机VHD格式解析到NTFS文件系统解析
本来的需求是XEN下的镜像取证,但这篇仅包括他支持的一种格式,就是VHD,此项目从头开始大概用了两周时间,中间遇到了很多让人头大的问题,光是思考的笔记就写了十几页纸,不过实际上并没有那么难,主要是很久 ...
- 数组去重的三种方法及from方法
直接上代码: var str="adbbckddwerivka"; var arr=str.split(""); console.log(arr); //ind ...
- To Build A Dev Env On Linux(Ubuntu)
Step1:System Installing 1)use iso image to Step2:Configuration Step3:Software Installing Step4:Other ...
- 请教 WINDOWSPHONE 有个人录了个传感器等硬件的视频,并且项目是完全开源的,大家有知道地址的吗?或者叫什么。
请教 WINDOWSPHONE 有个人录了个传感器等硬件的视频,并且项目是完全开源的,大家有知道地址的吗?或者叫什么.
- js两个时间相减
平常总会遇到需要算两个日期之间是多少天,以下是使用JavaScript算时间差多少天的: // 给日期类对象添加日期差方法,返回日期与diff参数日期的时间差,单位为天 Date.prototype. ...
- frame,bounds,center-三者的含义
frame与bounds的区别比较 frame,bounds,center-三者的含义 偶然觉的,这三个属性有时候定位的时候,需要用.于是就来搞清楚,到底frame,bounds,center 这三个 ...
- 【技术贴】同一台机器Tomcat7多版本共存配置文档
首先准备好自己下载的Tomcat7的绿色版,一定要是解压的绿色版不能使exe安装包.因为exe安装版很多变量不好配置,我以前最喜欢exe版了,方便快捷,但是我发现还是绿色解压版比较好,优化配置等也很好 ...
- Eclipse调试的一些小技巧
不要使用System.out.println作为调试工具 启用所有组件的详细的日志记录级别 使用一个日志分析器来阅读日志 1.条件断点 想象一下我们平时如何添加断点,通常的做法是双击行号的左边.在de ...
- 安装zabbix2.2.3
系统版本:CentOS 6.3_x86_64 zabbix版本:zabbix-2.2.3 zabbix服务端IP:172.16.10.72 1.yum安装LAMP环境 # yum -y install ...
- 【转】BLE 学习记录
原文网址:http://m.blog.csdn.net/blog/chiooo/43985401 BLE 学习记录 ANROID BLE 开发,基于 bluetoothlegatt 分析 mBluet ...