Skip to content

Commit

Permalink
jshint —> semistandard (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
corymsmith authored and daffl committed Oct 22, 2016
1 parent b02c8f7 commit b1987f6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 64 deletions.
31 changes: 0 additions & 31 deletions .jshintrc

This file was deleted.

1 change: 0 additions & 1 deletion .npmignore
@@ -1,5 +1,4 @@
.editorconfig
.jshintrc
.travis.yml
.babelrc
.idea/
Expand Down
17 changes: 13 additions & 4 deletions package.json
Expand Up @@ -37,11 +37,19 @@
"release:major": "npm run add-dist; npm version major && npm publish",
"compile": "rimraf lib/ && babel -d lib/ src/",
"watch": "babel --watch -d lib/ src/",
"jshint": "jshint src/. test/. --config",
"lint": "eslint-if-supported semistandard --fix",
"mocha": "mocha test/ --compilers js:babel-core/register",
"test": "npm run compile && npm run jshint && npm run mocha",
"test": "npm run compile && npm run lint && npm run mocha",
"start": "node example/app"
},
"semistandard": {
"env": [
"mocha"
],
"ignore": [
"/lib"
]
},
"directories": {
"lib": "lib"
},
Expand All @@ -57,15 +65,16 @@
"babelify": "^7.2.0",
"body-parser": "^1.15.0",
"browserify": "^13.0.0",
"eslint-if-supported": "^1.0.1",
"feathers": "^2.0.0",
"feathers-errors": "^2.0.1",
"feathers-rest": "^1.2.2",
"feathers-service-tests": "^0.8.0",
"feathers-socketio": "^1.3.3",
"jshint": "^2.9.1",
"localstorage-memory": "^1.0.2",
"mocha": "^3.0.0",
"nsp": "^2.2.0",
"rimraf": "^2.5.2"
"rimraf": "^2.5.2",
"semistandard": "^9.1.0"
}
}
43 changes: 21 additions & 22 deletions src/index.js
@@ -1,7 +1,7 @@
import { Service } from 'feathers-memory';

class LocalStorage extends Service {
constructor(options = {}) {
constructor (options = {}) {
super(options);
this._storageKey = options.name || 'feathers';
this._storage = options.storage || (typeof window !== 'undefined' && window.localStorage);
Expand All @@ -13,17 +13,16 @@ class LocalStorage extends Service {
}
}

ready() {
if(!this.store) {
ready () {
if (!this.store) {
return Promise.resolve(this._storage.getItem(this._storageKey))
.then(str => JSON.parse(str || '{}'))
.then(store => {
const keys = Object.keys(store);
const last = store[keys[keys.length - 1]];

// Current id is the id of the last item
this._uId = (keys.length && typeof last[this.id] !== 'undefined') ?
last[this.id] + 1 : 0;
this._uId = (keys.length && typeof last[this.id] !== 'undefined') ? last[this.id] + 1 : 0;

return (this.store = store);
});
Expand All @@ -32,8 +31,8 @@ class LocalStorage extends Service {
return Promise.resolve(this.store);
}

flush(data) {
if(!this._timeout) {
flush (data) {
if (!this._timeout) {
this._timeout = setTimeout(() => {
this._storage.setItem(this._storageKey, JSON.stringify(this.store));
delete this._timeout;
Expand All @@ -43,41 +42,41 @@ class LocalStorage extends Service {
return data;
}

execute(method, ... args) {
execute (method, ...args) {
return this.ready()
.then(() => super[method](... args));
.then(() => super[method](...args));
}

find(... args) {
return this.execute('find', ... args);
find (...args) {
return this.execute('find', ...args);
}

get(... args) {
return this.execute('get', ... args);
get (...args) {
return this.execute('get', ...args);
}

create(... args) {
return this.execute('create', ... args)
create (...args) {
return this.execute('create', ...args)
.then(data => this.flush(data));
}

patch(... args) {
return this.execute('patch', ... args)
patch (...args) {
return this.execute('patch', ...args)
.then(data => this.flush(data));
}

update(... args) {
return this.execute('update', ... args)
update (...args) {
return this.execute('update', ...args)
.then(data => this.flush(data));
}

remove(... args) {
return this.execute('remove', ... args)
remove (...args) {
return this.execute('remove', ...args)
.then(data => this.flush(data));
}
}

export default function init(options) {
export default function init (options) {
return new LocalStorage(options);
}

Expand Down
8 changes: 2 additions & 6 deletions test/index.test.js
@@ -1,5 +1,3 @@
/*jshint expr: true*/

import { base, example } from 'feathers-service-tests';
import errors from 'feathers-errors';
import feathers from 'feathers';
Expand Down Expand Up @@ -38,7 +36,6 @@ describe('Feathers Localstorage Service', () => {
})).then(() => {
return new Promise((resolve) => {
setTimeout(() => {

const data = JSON.parse(storage.getItem(name));
assert.deepEqual(data, {
0: {
Expand All @@ -63,7 +60,6 @@ describe('Feathers Localstorage Service', () => {
}).then(() => {
return new Promise((resolve) => {
setTimeout(() => {

const data = JSON.parse(storage.getItem(name));
assert.deepEqual(data, {
2: {
Expand Down Expand Up @@ -95,8 +91,8 @@ describe('Feathers Localstorage Service', () => {
return messageService.find().then((data) => {
assert.deepEqual(data, {
0: {
id: 0,
text: 'test 0'
id: 0,
text: 'test 0'
}
});
});
Expand Down

0 comments on commit b1987f6

Please sign in to comment.