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

Commit

Permalink
using es6 tests for fun and improvements and fixes to build process
Browse files Browse the repository at this point in the history
  • Loading branch information
tymondesigns committed Sep 17, 2015
1 parent a78a59e commit 5b18f2d
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 149 deletions.
16 changes: 8 additions & 8 deletions .gitdown/_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ locker.put('someKey', ['foo', 'bar']);
locker.put('someKey', function(current) {
current.push('baz');

return current
return current;
});

locker.get('someKey') // = ['foo', 'bar', 'baz']
locker.get('someKey'); // = ['foo', 'bar', 'baz']
```

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.
Expand Down Expand Up @@ -247,7 +247,7 @@ locker.namespace('somethingElse').count();
You can determine whether an item exists in the current namespace via

```js
locker.has('someKey') // true or false
locker.has('someKey'); // true or false
// or
locker.namespace('foo').has('bar');

Expand Down Expand Up @@ -353,7 +353,7 @@ app.controller('AppCtrl', ['$scope', function ($scope) {

$scope.foo = ['bar', 'baz'];

locker.get('foo') // = ['bar', 'baz']
locker.get('foo'); // = ['bar', 'baz']

}]);
```
Expand All @@ -365,9 +365,9 @@ app.controller('AppCtrl', ['$scope', function ($scope) {

locker.bind($scope, 'foo', 'someDefault');

$scope.foo // = 'someDefault'
$scope.foo; // = 'someDefault'

locker.get('foo') // = 'someDefault'
locker.get('foo'); // = 'someDefault'

}]);
```
Expand All @@ -380,9 +380,9 @@ app.controller('AppCtrl', ['$scope', function ($scope) {

locker.unbind($scope, 'foo');

$scope.foo // = undefined
$scope.foo; // = undefined

locker.get('foo') // = undefined
locker.get('foo'); // = undefined

}]);
```
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ http://www.jsdelivr.com/#!angular.locker

Simply download the zip file [HERE](https://github.com/tymondesigns/angular-locker/archive/master.zip) and include `dist/angular-locker.min.js` in your project.

1.64 kB Minified & gzipped.
1.65 kB Minified & gzipped.

<h2 id="usage">Usage</h2>

Expand Down Expand Up @@ -168,10 +168,10 @@ locker.put('someKey', ['foo', 'bar']);
locker.put('someKey', function(current) {
current.push('baz');

return current
return current;
});

locker.get('someKey') // = ['foo', 'bar', 'baz']
locker.get('someKey'); // = ['foo', 'bar', 'baz']
```

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.
Expand Down Expand Up @@ -300,7 +300,7 @@ locker.namespace('somethingElse').count();
You can determine whether an item exists in the current namespace via

```js
locker.has('someKey') // true or false
locker.has('someKey'); // true or false
// or
locker.namespace('foo').has('bar');

Expand Down Expand Up @@ -406,7 +406,7 @@ app.controller('AppCtrl', ['$scope', function ($scope) {

$scope.foo = ['bar', 'baz'];

locker.get('foo') // = ['bar', 'baz']
locker.get('foo'); // = ['bar', 'baz']

}]);
```
Expand All @@ -418,9 +418,9 @@ app.controller('AppCtrl', ['$scope', function ($scope) {

locker.bind($scope, 'foo', 'someDefault');

$scope.foo // = 'someDefault'
$scope.foo; // = 'someDefault'

locker.get('foo') // = 'someDefault'
locker.get('foo'); // = 'someDefault'

}]);
```
Expand All @@ -433,9 +433,9 @@ app.controller('AppCtrl', ['$scope', function ($scope) {

locker.unbind($scope, 'foo');

$scope.foo // = undefined
$scope.foo; // = undefined

locker.get('foo') // = undefined
locker.get('foo'); // = undefined

}]);
```
Expand Down
8 changes: 4 additions & 4 deletions dist/angular-locker.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@
*/
this._event = function (name, payload) {
if (this._options.eventsEnabled) {
$rootScope.$emit(name, angular.extend(payload, {
$rootScope.$emit('locker.' + name, angular.extend(payload, {
driver: this._options.driver,
namespace: this._namespace,
}));
Expand All @@ -294,9 +294,9 @@
var oldVal = this._getItem(key);
this._driver.setItem(this._getPrefix(key), this._serialize(value));
if (this._exists(key) && ! angular.equals(oldVal, value)) {
this._event('locker.item.updated', { key: key, oldValue: oldVal, newValue: value });
this._event('item.updated', { key: key, oldValue: oldVal, newValue: value });
} else {
this._event('locker.item.added', { key: key, value: value });
this._event('item.added', { key: key, value: value });
}
} catch (e) {
if (['QUOTA_EXCEEDED_ERR',
Expand Down Expand Up @@ -363,7 +363,7 @@
if (! this._exists(key)) return false;

this._driver.removeItem(this._getPrefix(key));
this._event('locker.item.forgotten', { key: key });
this._event('item.forgotten', { key: key });

return true;
};
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-locker.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/angular-locker.min.js.map

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import gulp from 'gulp';
import {task as fizzy} from 'fizzy';
import pkg from './package.json';
import {paths, banner} from './config';
import runSequence from 'run-sequence';

// Lint the JS
gulp.task('lint', fizzy('lint', { src: paths.scripts }));
Expand Down Expand Up @@ -32,7 +33,9 @@ gulp.task('gitdown', fizzy('gitdown', {
}));

// Define the build tasks
gulp.task('build', ['lint', 'jscs', 'scripts', 'test', 'gitdown']);
gulp.task('build', (cb) => {
runSequence(['lint', 'jscs', 'scripts', 'test'], 'gitdown', cb);
});

// Increment versions
gulp.task('version', fizzy('version', {
Expand All @@ -41,8 +44,8 @@ gulp.task('version', fizzy('version', {
}));

// release a new version
gulp.task('release', ['version'], () => {
gulp.run('build');
gulp.task('release', (cb) => {
runSequence('version', 'build', cb);
});

// Watch for changes
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@
},
"devDependencies": {
"angular-mocks": ">=1.2.0 <2.0.0",
"babel": "^5.5.8",
"fizzy": "^0.2.1",
"babel-core": "^5.7.4",
"fizzy": "^0.3.3",
"gulp": "~3.9.0",
"karma": "^0.12.16",
"karma-babel-preprocessor": "^5.2.2",
"karma-coverage": "~0.2.6",
"karma-jasmine": "~0.2.0",
"karma-notify-reporter": "^0.1.1",
"karma-phantomjs-launcher": "^0.1.4",
"karma-sauce-launcher": "^0.2.10",
"karma-spec-reporter": "0.0.13"
"karma-spec-reporter": "0.0.13",
"run-sequence": "^1.1.3"
},
"main": "dist/angular-locker.min.js",
"scripts": {
Expand Down
8 changes: 4 additions & 4 deletions src/angular-locker.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@
*/
this._event = function (name, payload) {
if (this._options.eventsEnabled) {
$rootScope.$emit(name, angular.extend(payload, {
$rootScope.$emit('locker.' + name, angular.extend(payload, {
driver: this._options.driver,
namespace: this._namespace,
}));
Expand All @@ -294,9 +294,9 @@
var oldVal = this._getItem(key);
this._driver.setItem(this._getPrefix(key), this._serialize(value));
if (this._exists(key) && ! angular.equals(oldVal, value)) {
this._event('locker.item.updated', { key: key, oldValue: oldVal, newValue: value });
this._event('item.updated', { key: key, oldValue: oldVal, newValue: value });
} else {
this._event('locker.item.added', { key: key, value: value });
this._event('item.added', { key: key, value: value });
}
} catch (e) {
if (['QUOTA_EXCEEDED_ERR',
Expand Down Expand Up @@ -363,7 +363,7 @@
if (! this._exists(key)) return false;

this._driver.removeItem(this._getPrefix(key));
this._event('locker.item.forgotten', { key: key });
this._event('item.forgotten', { key: key });

return true;
};
Expand Down
6 changes: 4 additions & 2 deletions test/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ module.exports = function (config) {
'karma-sauce-launcher',
'karma-jasmine',
'karma-coverage',
'karma-notify-reporter'
'karma-notify-reporter',
'karma-babel-preprocessor'
],
preprocessors: {
'../src/*.js': ['coverage']
'../src/*.js': ['coverage'],
'../test/**/*.js': ['babel']
},

sauceLabs: {
Expand Down
16 changes: 6 additions & 10 deletions test/mock/storageMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,34 @@
'use strict';

function storageMock() {
var store = {};
let store = {};

Object.defineProperties(store, {
setItem: {
value: function (key, value) {
value: (key, value) => {
store[key] = value || '';
},
enumerable: false,
writable: true
},
getItem: {
value: function (key) {
return store[key];
},
value: (key) => store[key],
enumerable: false,
writable: true
},
removeItem: {
value: function (key) {
value: (key) => {
delete store[key];
},
enumerable: false,
writable: true
},
length: {
get: function () {
return Object.keys(store).length;
},
get: () => Object.keys(store).length,
enumerable: false
},
clear: {
value: function () {
value: () => {
store = {};
},
enumerable: false,
Expand Down
Loading

0 comments on commit 5b18f2d

Please sign in to comment.