Skip to content

Commit

Permalink
readme update
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaly Puzrin committed Nov 11, 2016
1 parent bb72011 commit 605e5b7
Showing 1 changed file with 18 additions and 31 deletions.
49 changes: 18 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ bag.js - JS / CSS loader + KV storage
[![Build Status](https://travis-ci.org/nodeca/bag.js.svg?branch=master)](https://travis-ci.org/nodeca/bag.js)
[![NPM version](https://img.shields.io/npm/v/bagjs.svg?style=flat)](https://www.npmjs.org/package/bagjs)

__bag.js__ is loader for `.js` / `.css` and other files, that uses browser
stores for caching. Consider it as alternative for other types of loaders for
modern browsers, that reduce number of server requests, especially for mobile
devices. Also __bag.js__ can be used as simple key/value storage, that doesn't
require you to know details about IndexedDB and WebSQL.
> __bag.js__ is loader for `.js` / `.css` and other files, that uses
IndexedDB/ WebSQL / localStorage for caching. Consider it as alternative for
other types of loaders for modern browsers, that reduce number of server
requests, especially for mobile devices. Also __bag.js__ can be used as simple
key/value storage, that doesn't require you to know details about IndexedDB
and WebSQL.

This project is inspired by __[basket.js](http://addyosmani.github.io/basket.js/)__,
but provides more safe storages for big assets and universal key/value interface.
Expand Down Expand Up @@ -50,12 +51,11 @@ Simple:
var bag = new window.Bag();

bag.require(['/site.css', '/jquery.js', '/site.js'])
.then(function () {
.then(() => {
// code to run after loading
// ...
}, function (err) {
console.log('loading error: ', err);
});
})
.catch(err => console.log('loading error: ', err));
```

Advanced:
Expand All @@ -80,24 +80,21 @@ var files = [
];

bag.require(files)
.then(function(data) {
.then(data => {
console.log('loaded', data);
})
.then(null, function (err) {
console.log(err);
});
.catch(err => console.log(err));
})
```

You can skip `new` keyword. Also, you can use callbacks:

```js
window.Bag().require([ '/site.css', '/site.js']
.then(function (data) {
.then(data => {
console.log(data);
}, function (err) {
console.log('loading error: ', err);
});
})
.catch(err => console.log(err));
```
Using as key/value storage:
Expand All @@ -107,18 +104,10 @@ var obj = { lorem: 'ipsum' };
var bag = new window.Bag();

bag.set('dolorem', obj)
.then(function () {
return bag.get('dolorem');
})
.then(function (data) {
console.log('Loaded data:\n', data);
})
.catch(function (err) {
console.log(err);
})
.then(function () {
return bag.remove('dolorem');
});
.then(() => bag.get('dolorem'));
.then(data => console.log('Loaded data:\n', data));
.catch(err => console.log(err));
.then(() => bag.remove('dolorem'));
```
Expand Down Expand Up @@ -196,8 +185,6 @@ Put data into storage under `key` name.
- `data` - JS object to store. We currently support only objects, serializable
by JSON. Don't try to put functions or arraybuffers.
- `expire` - Expiration time in seconds. Don't expire by default.
- `callback(err)` - Function to call when complete. `err` contains error
on fail.
### .remove(key) -> Promise
Expand Down

0 comments on commit 605e5b7

Please sign in to comment.