Skip to content

Commit 739f99b

Browse files
committed
feat: version 1.0 to use localForage >1.0 !
Be careful, many breaking changes, read the changelog !
1 parent 013c6d0 commit 739f99b

File tree

10 files changed

+553
-365
lines changed

10 files changed

+553
-365
lines changed

CHANGELOG.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
<a name="1.0.0"></a>
2+
# 1.0.0 (2014-10-17)
3+
4+
## Features
5+
- You can now use multiple instances of localForage (see the [Readme file](https://github.com/ocombe/angular-localForage/blob/master/README.md) for more info).
6+
- You can use a `name` option with bind and with the directive to specify which instance to use.
7+
- Slightly better examples (I could do much better)
8+
9+
## Breaking changes
10+
- The following deprecated functions have been removed: getDriver, set, get, remove, clearAll, getKeyAt, getLength
11+
- getKeys is now deprecated, use the function keys instead (following the naming convention from localForage).
12+
- Because localForage now takes into account the prefix for localStorage, this lib will no longer add its own prefix to localStorage variables.
13+
If you want to ensure compability with values stored in localStorage before this release, you need to add `oldPrefix: true` to your provider's configuration:
14+
```js
15+
$localForageProvider.config({
16+
oldPrefix: true
17+
});
18+
```
19+
If you don't do that, you won't be able to access those old data, and they will stay in localStorage.
20+
This doesn't affect other storages (indexedDB & WebSQL).
21+
- The method `bind` and the directive have changed: `storeName` has been replaced by `scopeKey` to avoid confusion with the `storeName` from config and to be more self explicit. `key` is now the name of the storage key.
22+
- The method `unbind` now takes only 2 parameters (scope & key, or scope & config object). `storeName` has also been replaced by `scopeKey`.
23+
24+
## Documentation
25+
- Better doc on the directive
26+
- General cleanup
27+
- Doc for the multiple instances
28+
29+
130
<a name="0.2.10"></a>
231
# 0.2.10 (2014-09-08)
332

README.md

Lines changed: 56 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -18,103 +18,92 @@ This angularJS module is a rewrite of [angular-local-storage by grevory](https:/
1818
- Use the service or the directive
1919

2020
## Usage :
21-
- Download the project or install via bower ```bower install angular-localforage``` or npm ```npm install angular-localforage```
21+
- Download the project or install via bower `bower install angular-localforage` or npm `npm install angular-localforage`
2222
- Download localForage https://github.com/mozilla/localForage
23-
- Put angular-localStorage.js and localforage.js into you project
24-
- Add the module ```LocalForageModule``` to your application
23+
- Put angular-localForage.js and localforage.js into you project
24+
- Add the module `LocalForageModule` to your application
2525
```js
2626
angular.module('yourModule', ['LocalForageModule']);
2727
```
28-
- (optional) Configure the ```$localForageProvider```
29-
```js
30-
angular.module('yourModule', ['LocalForageModule'])
31-
.config(['$localForageProvider', function($localForageProvider){
32-
$localForageProvider.config({
33-
driver : 'localStorageWrapper', // if you want to force a driver
34-
name : 'myApp', // name of the database and prefix for your data
35-
version : 1.0, // version of the database, you shouldn't have to use this
36-
storeName : 'keyvaluepairs', // name of the table
37-
description : 'some description'
38-
});
39-
}]);
40-
```
41-
- Use the ```$localForage``` service or the ```local-forage``` directive
28+
- (optional) Configure the `$localForageProvider`. See [below](#configure-the-provider-) for details.
29+
- Use the `$localForage` service or the `local-forage` directive
4230
```js
4331
angular.module('yourModule', ['LocalForageModule'])
4432
.controller('yourCtrl', ['$scope', '$localForage', function($scope, $localForage) {
45-
// Start fresh
46-
$localForage.clearAll();
4733
$localForage.setItem('myName','Olivier Combe').then(function() {
4834
$localForage.getItem('myName').then(function(data) {
4935
var myName = data;
5036
});
5137
});
52-
53-
$scope.params = {
54-
test: 'value'
55-
};
5638
}]);
5739
```
5840
```html
59-
<div local-forage="params"></div>
41+
<input local-forage="{key: 'autoStoredKey', name: 'myApp', scopeKey: 'myObj.myVar', defaultValue: 'this is the default value'}" ng-model="myObj.myVar" placeholder="This will be auto stored">
6042
```
6143

6244
## Functions :
63-
- ```setDriver(driver)```: you can force the driver to use, check the [localForage documentation](https://github.com/mozilla/localForage#driver-selection-ie-forcing-localstorage) for more information
45+
- `setDriver(driver)`: you can force the driver to use, check the [localForage documentation](https://github.com/mozilla/localForage#driver-selection-ie-forcing-localstorage) for more information
6446

65-
- ```driver()```: returns the current localForage driver (sync)
47+
- `driver()`: returns the current localForage driver (sync)
6648

67-
- ```setItem(key, value)```: stores data (async, promise)
49+
- `setItem(key, value)`: stores data (async, promise)
6850

69-
- ```getItem(key)```: retrieves stored data (async, promise)
51+
- `getItem(key)`: retrieves stored data (async, promise)
7052

71-
- ```removeItem(key)```: removes stored data (async, promise)
53+
- `removeItem(key)`: removes stored data (async, promise)
7254

73-
- ```clear()```: removed all stored data for your application based on the app prefix (async, promise)
55+
- `clear()`: removed all stored data for your application based on the app prefix (async, promise)
7456

75-
- ```key(n)```: retrieves the key at n position in storage. Used internally for clearAll and getKeys functions. It doesn't take prefix into account (async, promise)
57+
- `key(n)`: retrieves the key at n position in storage. It doesn't take the prefix into account if you use localStorage (async, promise)
7658

77-
- ```getKeys(driver)```: returns all the keys used for storage in your application. Be careful with it if you use localstorage because it will return all the keys (not just the ones with your prefix) (async, promise)
59+
- `keys()`: returns all the keys used for storage in your application (async, promise)
7860

79-
- ```length(driver)```: returns the number of items stored. Used internally for clearAll and getKeys functions. Be careful with it if you use localstorage because it will return all the keys (not just the ones with your prefix) (async, promise)
61+
- `length()`: returns the number of items stored (async, promise)
8062

81-
- ```bind($scope, key/params object)```: lets you directly bind a LocalForage value to a $scope variable
63+
- `bind($scope, key/params object)`: lets you directly bind a LocalForage value to a $scope variable (async, promise)
8264
```js
83-
$localForage.bind($scope, 'params');
65+
$localForage.bind($scope, 'myStorageKey');
8466
```
67+
8568
```js
8669
$localForage.bind($scope, {
87-
key: 'params',
88-
defaultValue: {test: 'my test'},
89-
storeName: 'myStoreName'
70+
key: 'myStorageKey', // required
71+
defaultValue: {test: 'my test'}, // a default value
72+
scopeKey: 'myObj.myVar', // the name of the scope key (if you want it to be different from key)
73+
name: 'myApp' // instance name
9074
});
9175
```
9276

93-
- ```unbind($scope, key[, storeName])```: lets you unbind a variable from localForage while removing the value from both
77+
- `unbind($scope, key[, scopeKey])`: lets you unbind a variable from localForage while removing the value from both the scope and the storage (async, promise)
9478

9579
## Directive :
96-
You can directly bind a scope value from within your html :
97-
```js
98-
angular.module('yourModule', ['LocalForageModule']).controller('yourCtrl', ['$scope', function($scope) {
99-
$scope.params = {
100-
test: 'value'
101-
};
102-
}]);
103-
```
80+
You can directly bind a scope value from within your html. With the `local-forage` directive, you can either use just the key parameter:
10481
```html
105-
<div local-forage="params"></div>
82+
<input local-forage="autoStoredKey" ng-model="autoStoredKey" placeholder="This will be auto stored">
10683
```
84+
85+
Or give an object parameter:
10786
```html
108-
<div local-forage="{key: 'params', storeName: 'myStoreName'}"></div>
87+
<input local-forage="{key: 'autoStoredKey', name: 'myApp', scopeKey: 'myObj.myVar', defaultValue: 'this is the default value'}" ng-model="myObj.myVar" placeholder="This will be auto stored">
10988
```
11089

90+
`key` is the only required parameter. The other options are:
91+
- `name`: if you want to store your values in a specific instance (See [below](#multiple-instances) for more info on multiple instances)
92+
- `scopeKey`: if you want to store the value in the scope under a different key from the one in storage. You can for example use a specific key of an object by using `myObj.myVar`
93+
- `defaultValue`: if you want to define a ...default value
94+
11195
## Configure the provider :
112-
You can configure the ```$localForageProvider``` to set your own prefix for storage. By default ```lf``` is used.
96+
You can configure the `$localForageProvider`. Any parameter that you set here will be the default for any new localforage instance.
97+
You can for example set your own prefix for storage (by default `lf` is used).
11398
```js
11499
angular.module('yourModule', ['LocalForageModule'])
115100
.config(['$localForageProvider', function($localForageProvider){
116101
$localForageProvider.config({
117-
name: 'yourprefix'
102+
driver : 'localStorageWrapper', // if you want to force a driver
103+
name : 'myApp', // name of the database and prefix for your data, it is "lf" by default
104+
version : 1.0, // version of the database, you shouldn't have to use this
105+
storeName : 'keyvaluepairs', // name of the table
106+
description : 'some description'
118107
});
119108
}]);
120109
```
@@ -133,14 +122,24 @@ $rootScope.$broadcast('LocalForageModule.setItem', {key: key, newvalue: value, d
133122
$rootScope.$broadcast('LocalForageModule.removeItem', {key: key, driver: localforage.driver});
134123
```
135124

136-
And finally you can set the driver.
125+
## Multiple instances
126+
You can use multiple instances of localForage at the same time. To create a new instance, call `createInstance` with a config object (sync):
137127
```js
138-
angular.module('yourModule', ['LocalForageModule'])
139-
.config(['$localForageProvider', function($localForageProvider){
140-
$localForageProvider.setDriver('localStorageWrapper');
141-
}]);
128+
var lf2 = $localForage.createInstance({
129+
name: '2nd',
130+
driver: 'localStorageWrapper'
131+
});
142132
```
143133

134+
The parameters will inherit the default parameters that you might have configured in the config phase of your application (See [above](#configure-the-provider-) for details), but the new config object will overwrite them.
135+
It means that you can have one instance using localStorage, and one instance using indexedDB/WebSQL, at the same time !
136+
The instance will take the name that you will define in the config object. You can get an instance previously created by using the `instance` method:
137+
```js
138+
var lf2 = $localForage.instance('2nd');
139+
```
140+
141+
The `instance` method will return the default instance if you don't give a name parameter.
142+
144143
## Unit tests
145144
Download the required libs :
146145

@@ -154,7 +153,7 @@ Then start the tests with :
154153
npm test
155154
```
156155

157-
It will launch Chrome and Firefox, edit karma.conf.js if you want to change something.
156+
It will launch Chrome and Firefox, edit karma.conf.js if you want to change something. We could use more tests, see "contributing" below.
158157

159158
##Contributing
160159

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "angular-localforage",
33
"main": "dist/angular-localForage.js",
4-
"version": "0.2.10",
4+
"version": "1.0.0",
55
"homepage": "https://github.com/ocombe/angular-localForage",
66
"authors": [
77
"Olivier Combe <olivier.combe@gmail.com>"
@@ -35,7 +35,7 @@
3535
"angular-mocks": "1.2.x - 1.3.x"
3636
},
3737
"dependencies": {
38-
"localforage": "0.9.2",
38+
"localforage": "1.0.4",
3939
"angular": "1.2.x - 1.3.x"
4040
}
4141
}

0 commit comments

Comments
 (0)