Skip to content
This repository was archived by the owner on Mar 8, 2021. It is now read-only.

Commit bf8b9e4

Browse files
committed
2.0.0 release
1 parent e502aa2 commit bf8b9e4

7 files changed

Lines changed: 90 additions & 15 deletions

File tree

.gitdown/_usage.md

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@ Configure via `lockerProvider` (*optional*)
1212

1313
```js
1414
.config(['lockerProvider', function config(lockerProvider) {
15-
lockerProvider.setDefaultDriver('session')
16-
.setDefaultNamespace('myAppName')
17-
.setSeparator('.')
18-
.setEventsEnabled(false);
15+
lockerProvider.defaults({
16+
driver: 'session',
17+
namespace: 'myApp',
18+
separator: '.',
19+
eventsEnabled: true,
20+
extend: {}
21+
});
1922
}]);
2023
```
2124

22-
*Note*: You can also pass `false` into `setDefaultNamespace()` if you prefer to not have a namespace in your keys.
25+
*Note*: You can also pass `false` to `namespace` if you prefer to not have a namespace in your keys.
2326

2427
inject `locker` into your controller/service/directive etc
2528

@@ -29,6 +32,28 @@ inject `locker` into your controller/service/directive etc
2932
}]);
3033
```
3134

35+
#### Extending Locker
36+
37+
You can pass in an implementation of the [Storage Interface](https://developer.mozilla.org/en-US/docs/Web/API/Storage) to the `lockerProvider` as described above. e.g.
38+
39+
```js
40+
lockerProvider.defaults({
41+
extend: {
42+
myCustomStore: function () {
43+
// getItem
44+
// setItem
45+
// removeItem
46+
// etc
47+
}
48+
}
49+
});
50+
51+
// then use as normal
52+
locker.driver('myCustomStore').put('foo', 'bar');
53+
```
54+
55+
See my [storageMock](https://github.com/tymondesigns/angular-locker/blob/master/test/mock/storageMock.js) for an example on how to define a custom implementation.
56+
3257
----------------------------
3358

3459
### Switching storage drivers
@@ -96,6 +121,15 @@ locker.put('someKey', function(current) {
96121
locker.get('someKey') // = ['foo', 'bar', 'baz']
97122
```
98123

124+
If the current value is not already set then you can pass a third parameter as a default that will be returned instead. e.g.
125+
126+
```js
127+
// given locker.get('foo') is not defined
128+
locker.put('foo', function (current) {
129+
// current will equal 'bar'
130+
}, 'bar');
131+
```
132+
99133
#### adding multiple items at once by passing a single object
100134

101135
This will add each key/value pair as a **separate** item in storage

README.md

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,17 @@ Configure via `lockerProvider` (*optional*)
6565

6666
```js
6767
.config(['lockerProvider', function config(lockerProvider) {
68-
lockerProvider.setDefaultDriver('session')
69-
.setDefaultNamespace('myAppName')
70-
.setSeparator('.')
71-
.setEventsEnabled(false);
68+
lockerProvider.defaults({
69+
driver: 'session',
70+
namespace: 'myApp',
71+
separator: '.',
72+
eventsEnabled: true,
73+
extend: {}
74+
});
7275
}]);
7376
```
7477

75-
*Note*: You can also pass `false` into `setDefaultNamespace()` if you prefer to not have a namespace in your keys.
78+
*Note*: You can also pass `false` to `namespace` if you prefer to not have a namespace in your keys.
7679

7780
inject `locker` into your controller/service/directive etc
7881

@@ -82,6 +85,28 @@ inject `locker` into your controller/service/directive etc
8285
}]);
8386
```
8487

88+
<h4 id="usage-adding-to-your-project-extending-locker">Extending Locker</h4>
89+
90+
You can pass in an implementation of the [Storage Interface](https://developer.mozilla.org/en-US/docs/Web/API/Storage) to the `lockerProvider` as described above. e.g.
91+
92+
```js
93+
lockerProvider.defaults({
94+
extend: {
95+
myCustomStore: function () {
96+
// getItem
97+
// setItem
98+
// removeItem
99+
// etc
100+
}
101+
}
102+
});
103+
104+
// then use as normal
105+
locker.driver('myCustomStore').put('foo', 'bar');
106+
```
107+
108+
See my [storageMock](https://github.com/tymondesigns/angular-locker/blob/master/test/mock/storageMock.js) for an example on how to define a custom implementation.
109+
85110
----------------------------
86111

87112
<h3 id="usage-switching-storage-drivers">Switching storage drivers</h3>
@@ -149,6 +174,15 @@ locker.put('someKey', function(current) {
149174
locker.get('someKey') // = ['foo', 'bar', 'baz']
150175
```
151176

177+
If the current value is not already set then you can pass a third parameter as a default that will be returned instead. e.g.
178+
179+
```js
180+
// given locker.get('foo') is not defined
181+
locker.put('foo', function (current) {
182+
// current will equal 'bar'
183+
}, 'bar');
184+
```
185+
152186
<h4 id="usage-adding-items-to-locker-adding-multiple-items-at-once-by-passing-a-single-object">adding multiple items at once by passing a single object</h4>
153187

154188
This will add each key/value pair as a **separate** item in storage

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-locker",
3-
"version": "1.2.1",
3+
"version": "2.0.0",
44
"homepage": "https://github.com/tymondesigns/angular-locker",
55
"authors": [
66
"Sean Tymon <tymon148@gmail.com>"

changes.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,11 @@ lockerProvider.defaults({
1515

1616
##### General
1717

18-
- Reduced size of minified file by removing *now* unnecessary functions.
18+
- Added ability to extend locker at the config stage
19+
- Added `keys()` method to return an array of keys that exist within the current driver/namespace
20+
- Reduced size of minified file by removing *now* unnecessary functions
21+
- Adding third default parameter to `put()` method
22+
- Hugely refactored and simplified Gulp build process
23+
- Added [jscs](http://jscs.info/) to enforce coding style
24+
- Namespaces can now contain the separator without any issues
25+
- Lots of micro optimisations

dist/angular-locker.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/angular-locker.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-locker",
3-
"version": "1.2.1",
3+
"version": "2.0.0",
44
"description": "A simple & configurable abstraction for local/session storage in angular projects",
55
"author": "@tymondesigns",
66
"license": "MIT",

0 commit comments

Comments
 (0)