Skip to content

Commit

Permalink
exports creation function instead of actual object
Browse files Browse the repository at this point in the history
added test using mocha and chai
added code styling using standardjs
  • Loading branch information
psperber committed Oct 29, 2017
1 parent 11af1f9 commit f853f2a
Show file tree
Hide file tree
Showing 5 changed files with 3,337 additions and 30 deletions.
36 changes: 23 additions & 13 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
value: true
});
var Store = require('electron-store');
var store = new Store({});

exports.default = {
var createElectronStorage = function createElectronStorage() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
electronStoreOpts = _ref.electronStoreOpts;

var store = new Store(electronStoreOpts || {});

console.log(store);

return {
getItem: function getItem(key) {
return new Promise(function (resolve) {
resolve(store.get(key));
});
return new Promise(function (resolve) {
resolve(store.get(key));
});
},
setItem: function setItem(key, item) {
return new Promise(function (resolve) {
resolve(store.set(key, item));
});
return new Promise(function (resolve) {
resolve(store.set(key, item));
});
},
removeItem: function removeItem(key) {
return new Promise(function (resolve) {
resolve(store.delete(key));
});
return new Promise(function (resolve) {
resolve(store.delete(key));
});
}
};
};
};

exports.default = createElectronStorage;
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "redux-persist-electron-storage",
"version": "1.0.1",
"version": "1.1.0",
"description": "Redux persist adaptor for electon-store",
"main": "lib/index.js",
"repository": {
Expand All @@ -10,13 +10,19 @@
"author": "Philipp Sperber",
"license": "MIT",
"scripts": {
"build": "babel src -d lib"
"build": "babel src -d lib",
"test": "standard src/* && electron-mocha"
},
"dependencies": {
"electron-store": "^1.3.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.6.1"
"babel-preset-env": "^1.6.1",
"chai": "^4.1.2",
"electron": "^1.7.9",
"electron-mocha": "^4.0.3",
"mocha": "^4.0.1",
"standard": "*"
}
}
33 changes: 19 additions & 14 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
const Store = require('electron-store');
const store = new Store({});
const Store = require('electron-store')

export default {
const createElectronStorage = ({electronStoreOpts} = {}) => {
const store = new Store(electronStoreOpts || {})

return {
getItem: (key) => {
return new Promise((resolve) => {
resolve(store.get(key));
});
return new Promise((resolve) => {
resolve(store.get(key))
})
},
setItem: (key, item) => {
return new Promise((resolve) => {
resolve(store.set(key, item));
});
return new Promise((resolve) => {
resolve(store.set(key, item))
})
},
removeItem: (key) => {
return new Promise((resolve) => {
resolve(store.delete(key));
});
},
};
return new Promise((resolve) => {
resolve(store.delete(key))
})
}
}
}

export default createElectronStorage
45 changes: 45 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const createElectronStorage = require('../lib').default
const assert = require('chai').assert

describe('Initialisation', function () {
it('no args', function () {
const storage = createElectronStorage()
assert.isObject(storage, 'created storage is not an object')
})

describe('args', function () {
it('encryptionKey', function () {
const storage = createElectronStorage({
electronStoreOpts: {
encryptionKey: 'a'
}
})
assert.isObject(storage, 'created storage is not an object')
})
})
})

describe('Functions', function () {
const storage = createElectronStorage()

it('setItem', function () {
return storage.setItem('key', 'value')
})

it('getItem', function (done) {
storage.getItem('key')
.then(function (value) {
assert.equal(value, 'value')
done()
})
})

it('removeItem', function (done) {
storage.removeItem('key')
.then(storage.getItem('key'))
.then(function (value) {
assert.isUndefined(value)
done()
})
})
})
Loading

0 comments on commit f853f2a

Please sign in to comment.