Backbone.localStorage

A localStorage adapter for Backbone.js

  • 所有者: jeromegn/Backbone.localStorage
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

Backbone localStorage Backend

Build Status
Coverage Status
npm version

An adapter that replaces Backbone.sync to save to window.localStorage
instead of to the server.

Note Backbone LocalStorage v2 changes the API to work more with ES6 modules.
See Upgrade Notes for more details.

Usage

Import backbone.localstorage and attach it to your models and collections:

import {Collection, Model} from 'backbone';
import {LocalStorage} from 'backbone.localstorage';

const SomeCollection = Collection.extend({

  localStorage: new LocalStorage('SomeCollection'), // Uniquely identify this

});

const SomeModel = Model.extend({

  localStorage: new LocalStorage('SomeModel')

});

To synchronise with the server, you can pass the ajaxSync flag to any options:

const myModel = new SomeModel();
myModel.fetch({
  ajaxSync: true  // Fetches from the server
});

myModel.save({
  new: "value"
}, {
  ajaxSync: true  // Pushes back to the server
});

Upgrade Notes

Backbone LocalStorage is now built using ES6. It should be fully compatible with
v1 with one difference: Instead of exporting the LocalStorage class as a
default module, v2 exports it as a named variable. Below are examples covering
the changes:

JavaScript ES5

In v1:

var LocalStorage = require('backbone.localstorage');

In v2:

var localStorage = require('backbone.localstorage');
var LocalStorage = localStorage.LocalStorage;

JavaScript ES6+

In v1:

import LocalStorage from 'backbone.localstorage';

In v2:

import {LocalStorage} from 'backbone.localstorage';

Contributing

Install NodeJS and run yarn or npm i to get your dependencies, then:

  1. Open an issue identifying the fault
  2. Provide a fix, with tests demonstrating the issue
  3. Run npm test
  4. Create a pull request

Acknowledgments

主要指标

概览
名称与所有者jeromegn/Backbone.localStorage
主编程语言JavaScript
编程语言JavaScript (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2010-10-25 15:01:15
推送于2023-10-20 09:45:01
最后一次提交2021-03-18 08:52:48
发布数17
最新版本名称2.0.0 (发布于 )
第一版名称v1.1.0 (发布于 )
用户参与
星数1.9k
关注者数67
派生数677
提交数294
已启用问题?
问题数105
打开的问题数10
拉请求数78
打开的拉请求数0
关闭的拉请求数49
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?