Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/neofonie/ampersand-sync-localforage
localForage sync adapter for Ampersand.js
https://github.com/neofonie/ampersand-sync-localforage
ampersand ampersand-sync-localforage javascript localforage localstorage sync sync-adapters
Last synced: 1 day ago
JSON representation
localForage sync adapter for Ampersand.js
- Host: GitHub
- URL: https://github.com/neofonie/ampersand-sync-localforage
- Owner: Neofonie
- License: mit
- Created: 2014-09-01T16:23:11.000Z (over 10 years ago)
- Default Branch: main
- Last Pushed: 2024-10-31T05:55:19.000Z (3 months ago)
- Last Synced: 2024-10-31T06:25:22.576Z (3 months ago)
- Topics: ampersand, ampersand-sync-localforage, javascript, localforage, localstorage, sync, sync-adapters
- Language: JavaScript
- Size: 1.59 MB
- Stars: 9
- Watchers: 6
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# ampersand-sync-localforage
![Build Status](https://github.com/Neofonie/ampersand-sync-localforage/actions/workflows/run_automated_tests.yml/badge.svg)
[![NPM version](https://badge.fury.io/js/ampersand-sync-localforage.svg)](http://badge.fury.io/js/ampersand-sync-localforage)> [localForage](https://localforage.github.io/localForage/) sync adapter for [Ampersand.js](http://ampersandjs.com)
---
This module overrides the sync method of your Ampersand models and collections to use [localForage](https://localforage.github.io/localForage/), a library that provides a unified API for accessing multiple browser storage options (IndexedDB, WebSQL, localStorage). localForage will use the best available option by default.
**WARNING:** This project is feature complete for our current needs. But if you encounter some rough edges or missing functionality feel free to file an issue or submit a pull request, to help make this library the best it can be!
## Installation
```
npm install --save ampersand-sync-localforage
```## Usage
Just override the `sync` method on your models and collections with the function returned from the module.
### Models
Pass a string to the function. This string serves as a namespace that is prefixed to the model’s storage key.
```js
var Model = require('ampersand-model');
var localforage = require('ampersand-sync-localforage');module.exports = Model.extend({
sync: localforage('MyModelNamespace'),
props: {
id: 'string'
}
});
```### Collections
Pass a string to use as the collection’s unique storage key.
```js
var Collection = require('ampersand-rest-collection');
var localforage = require('ampersand-sync-localforage');
var MyModel = require('./my-model');module.exports = Collection.extend({
model: MyModel, // Must also be set up with localForage
sync: localforage('MyCollection'),
props: {
id: 'string'
}
});
```Under the hood, a collection is stored as a list of model IDs. Each model has its own entry in whatever storage option is being used.
## Development
You’ll need [Node.js](http://nodejs.org) and [Grunt](http://gruntjs.com/getting-started#installing-the-cli).
This project uses [Karma](http://karma-runner.github.io) to run the tests. In watch mode it launches Firefox, Chrome, and [PhantomJS](http://phantomjs.org/). In single-run mode it launches PhantomJS only.
To watch files for changes and run JSHint and Karma automatically during development, use
```bash
grunt dev
```To run the linting and tests once, use
```bash
grunt
```## Credits
This project started as a port of [localForage Backbone](https://github.com/mozilla/localForage-backbone). It also draws inspiration from [ConneXNL's port](https://github.com/ConneXNL/ampersand-sync-localstorage) of [Backbone.localStorage](https://github.com/jeromegn/Backbone.localStorage). Of course, many thanks go to the Ampersand.js team, as well as the developers at Mozilla who provide the localForage library.
## License
Copyright (c) 2022 Neofonie
Licensed under the [MIT license](LICENSE).