client-storage

2.0.2 • Public • Published

client-storage

clientStoragelocalStorage的基础上支持集合


API

clientStoragewindow.localStorage的API基本一一对应,但也有特殊,例如.length

clientStorage 的属性&方法

  • setItem(key, value)
  • getItem(key)
  • removeItem(key)
  • clear()
  • key(number)
  • getLength()
  • Collection(name)

创建集合

var todos = new clientStorage.Collection('todos');

"集合对象"的属性&方法

  • create(model)
  • update(id, data)
  • destroy(id)
  • destroyAll()
  • find(id)
  • findAll()
  • getLength()

异步风格

上面的API是同步返回数据,下面的配置可以使返回值为Promise对象

clientStorage.config('async', true);

兼容

  • clientStorage是在window.localStorage上扩展的
  • 当使用参数async,使用了浏览器原生的Promise构造函数

由于上面两点,clientStorage存在很多兼容问题

注意: 传入参数async,只是其接口是promise对象,其实内部是同步执行的

Dependencies (0)

    Dev Dependencies (5)

    Package Sidebar

    Install

    npm i client-storage

    Weekly Downloads

    61

    Version

    2.0.2

    License

    ISC

    Last publish

    Collaborators

    • daifee