Skip to content

Commit

Permalink
Merge branch 'release/0.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gias Kay Lee committed Jul 19, 2013
2 parents 5ad6801 + 37e3252 commit e41b498
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
44 changes: 27 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ bower install ngstorage
Usage
=====

#### Require ngStorage and Inject the Services
### Require ngStorage and Inject the Services

```javascript
angular.module('app', [
Expand All @@ -35,9 +35,9 @@ angular.module('app', [
){});
```

#### Read and Write | [Demo](http://plnkr.co/edit/3vfRkvG7R9DgQxtWbGHz)
### Read and Write | [Demo](http://plnkr.co/edit/3vfRkvG7R9DgQxtWbGHz)

Pass `$localStorage` (or `$sessionStorage`) by reference to a hook under `$scope`:
Pass `$localStorage` (or `$sessionStorage`) by reference to a hook under `$scope` in plain ol' JavaScript:

```javascript
$scope.$storage = $localStorage;
Expand All @@ -51,15 +51,17 @@ And use it like you-already-know:
</body>
```

Optionally, specify a default value in plain ol' JavaScript:
> Optionally, specify default values using the `$default()` method:
>
> ```javascript
> $scope.$storage = $localStorage.$default({
> counter: 42
> });
> ```
```javascript
$scope.$storage.counter = $localStorage.counter || 42;
```
With this setup, changes will be automatically sync'd between `$scope.$storage`, `$localStorage`, and localStorage - even across different browser tabs!
With this setup, changes will be automatically sync'd between `$scope.$storage`, `$localStorage`, and localStorage.

#### Read and Write Alternative (Not Recommended) | [Demo](http://plnkr.co/edit/9ZmkzRkYzS3iZkG8J5IK)
### Read and Write Alternative (Not Recommended) | [Demo](http://plnkr.co/edit/9ZmkzRkYzS3iZkG8J5IK)
If you're not fond of the presence of `$scope.$storage`, you can always use watchers:
Expand All @@ -77,29 +79,37 @@ $scope.$watch(function() {
});
```
This, however, is not the way ngStorage is designed to be used with. As you can easily see by comparing the demos, this approach is clearly way more verbose, and may have potential performance implications as the values being watched quickly grow.
This, however, is not the way ngStorage is designed to be used with. As can be easily seen by comparing the demos, this approach is way more verbose, and may have potential performance implications as the values being watched quickly grow.

#### Delete | [Demo](http://plnkr.co/edit/o4w3VGqmp8opfrWzvsJy)
### Delete | [Demo](http://plnkr.co/edit/o4w3VGqmp8opfrWzvsJy)

Plain ol' JavaScript again, what else could you better expect?

```javascript
// Both will work
// Both will do
delete $scope.$storage.counter;
delete $localStorage.counter;
```

This will delete the corresponding entry inside the Web Storage.

#### Delete Everything | [Demo](http://plnkr.co/edit/YiG28KTFdkeFXskolZqs)
### Delete Everything | [Demo](http://plnkr.co/edit/YiG28KTFdkeFXskolZqs)

Theoretically this can also be done in the plain ol' way but, we've got a convenient method just for you:
If you wish to clear the Storage in one go, use the `$reset()` method:

```javascript
$localStorage.$clear();
$localStorage.$reset();
````

#### Permitted Values | [Demo](http://plnkr.co/edit/n0acYLdhk3AeZmPOGY9Z)
> Optionally, pass in an object you'd like the Storage to reset to:
>
> ```javascript
> $localStorage.$reset({
> counter: 42
> });
> ```
### Permitted Values | [Demo](http://plnkr.co/edit/n0acYLdhk3AeZmPOGY9Z)
You can store anything except those [not supported by JSON](http://www.json.org/js.html):
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngstorage",
"version": "0.1.0",
"version": "0.2.0",
"main": "./ngStorage.js",
"dependencies": {
"angular": "1.0.7"
Expand Down

0 comments on commit e41b498

Please sign in to comment.