Skip to content

Commit

Permalink
eslint corrections + moved 'stack' method between modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
dfahlander committed Apr 5, 2016
1 parent 1da8fea commit 2d42749
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 82 deletions.
28 changes: 28 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
}
},
"rules": {
"no-undef": ["error"],
"no-unused-vars": 1,
"no-console": 0,
"no-empty": 0
},
"globals": {
"indexedDB": false,
"IDBKeyRange": false,
"setTimeout": false,
"clearTimeout": false,
"setImmediate": false,
"console": false,
"self": false,
"window": false,
"global": false,
"navigator": false,
"chrome": false
}
}
85 changes: 40 additions & 45 deletions src/Dexie.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Events.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {slice, keys, isArray, asap, _global} from './utils';
import {nop, stoppableEventChain} from './chaining-functions';
import {exceptions} from './errors';

export default function Events(ctx, eventNames) {
export default function Events(ctx) {
var args = arguments;
var evs = {};
var rv = function (eventName, subscriber) {
Expand Down
4 changes: 2 additions & 2 deletions src/Promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var asap = _asap,

var operationsQueue = [];
var tickFinalizers = [];
function enqueueImmediate(fn, args) {
var enqueueImmediate = function (fn) {
operationsQueue.push([fn, slice(arguments, 1)]);
}

Expand Down Expand Up @@ -357,7 +357,7 @@ Promise.usePSD = function (psd, fn) {
} finally {
Promise.PSD = outerScope;
}
}
};

Promise._rootExec = _rootExec;
Promise._tickFinalize = function(callback) {
Expand Down
15 changes: 2 additions & 13 deletions src/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ var dexieErrorNames = [
'SubTransaction',
'Unsupported',
'Internal',
'DatabaseClosed',

'DatabaseClosed'
];

var idbDomErrorNames = [
Expand All @@ -40,7 +39,7 @@ var errorList = dexieErrorNames.concat(idbDomErrorNames);
var defaultTexts = {
VersionChanged: "Database version changed by other database connection",
DatabaseClosed: "Database has been closed"
}
};

//
// DexieError - base class of all out exceptions.
Expand Down Expand Up @@ -140,16 +139,6 @@ export function mapError (domError, message) {
return rv;
}

export function stack(error) {
if (error.stack) return error;
try {
throw new Error();
} catch (e) {
error.stack = e.stack;
}
return error;
}

export var fullNameExceptions = errorList.reduce((obj, name)=>{
if (["Syntax","Type","Range"].indexOf(name) === -1)
obj[name + "Error"] = exceptions[name];
Expand Down
25 changes: 17 additions & 8 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Apache License Version 2.0, January 2004, http://www.apache.org/licenses/
*/
import Promise from './Promise';
import {exceptions} from './errors';

export var keys = Object.keys;
export var isArray = Array.isArray;
Expand Down Expand Up @@ -69,11 +70,22 @@ export function miniTryCatch(fn, onerror) {
}
}

export function stack(error) {
if (error.stack) return error; // Provided error already has a stack
try {
var err = new Error(error.message || error); // In Chrome, stack is generated here.
if (err.stack) { error.stack = err.stack; return error; } // If stack was generated, set it.
// No stack. Other browsers only put the stack if we throw the error:
throw err;
} catch (e) {
error.stack = e.stack;
}
return error;
}

export function fail(err) {
// Get the call stack and return a rejected promise.
try { throw err; } catch (e) {
return Promise.reject(err);
}
return Promise.reject(stack(err));
}

export function getByKeyPath(obj, keyPath) {
Expand Down Expand Up @@ -162,10 +174,7 @@ export function deepClone(any) {
}

export function getObjectDiff(a, b, rv, prfx) {
// This is a simplified version that will always return keypaths on the root level.
// If for example a and b differs by: (a.somePropsObject.x != b.somePropsObject.x), we will return that "somePropsObject" is changed
// and not "somePropsObject.x". This is acceptable and true but could be optimized to support nestled changes if that would give a
// big optimization benefit.
// Compares objects a and b and produces a diff object.
rv = rv || {};
prfx = prfx || '';
for (var prop in a) if (a.hasOwnProperty(prop)) {
Expand All @@ -180,7 +189,7 @@ export function getObjectDiff(a, b, rv, prfx) {
rv[prfx + prop] = b[prop];// Primitive value changed
}
}
for (var prop in b) if (b.hasOwnProperty(prop) && !a.hasOwnProperty(prop)) {
for (prop in b) if (b.hasOwnProperty(prop) && !a.hasOwnProperty(prop)) {
rv[prfx+prop] = b[prop]; // Property added
}
return rv;
Expand Down
34 changes: 21 additions & 13 deletions test/tests-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,27 +514,35 @@ spawnedTest("bulkPut-catching errors", function*() {
});

spawnedTest("bulkPut-non-inbound-autoincrement", function*(){
let lastId = yield db.folks.bulkPut([
yield db.folks.bulkPut([
{ first: "Foo", last: "Bar"},
{ first: "Foo", last: "Bar2"},
{ first: "Foo", last: "Bar3"},
{ first: "Foo", last: "Bar4"}
]);
equal (yield db.folks.where('first').equals('Foo').count(), 4, "Should be 4 Foos");
equal (yield db.folks.where('last').equals('Bar').count(), 1, "Should be 1 Bar");
let newLastId = yield db.folks.bulkPut([
{ first: "Foo2", last: "BarA"},
{ first: "Foo2", last: "BarB"},
{ first: "Foo2", last: "BarC"},
{ first: "Foo2", last: "BarD"}
], [lastId - 3,
void 0,
lastId - 1,
void 0]);
});

spawnedTest("bulkPut - mixed inbound autoIncrement", function* () {
let lastId = yield db.users.bulkPut([
{ first: "Foo", last: "Bar"},
{ first: "Foo", last: "Bar2"},
{ first: "Foo", last: "Bar3"},
{ first: "Foo", last: "Bar4"}
]);
equal (yield db.users.where('first').equals('Foo').count(), 4, "Should be 4 Foos");
equal (yield db.users.where('last').equals('Bar').count(), 1, "Should be 1 Bar");
let newLastId = yield db.users.bulkPut([
{ id: lastId - 3, first: "Foo2", last: "BarA"}, // Will update "Foo Bar" to "Foo2 BarA"
{ first: "Foo2", last: "BarB"}, // Will create
{ id: lastId - 1, first: "Foo2", last: "BarC"}, // Will update "Foo Bar3" to "Foo2 BarC"
{ first: "Foo2", last: "BarD"} // Will create
]);
equal (newLastId, lastId + 2, "Should have incremented last ID twice now");
equal (yield db.folks.where('first').equals('Foo').count(), 2, "Should be 2 Foos now");
equal (yield db.folks.where('first').equals('Foo2').count(), 4, "Should be 4 Foo2s now");
let foo2s = yield db.folks.where('first').equals('Foo2').toArray();
equal (yield db.users.where('first').equals('Foo').count(), 2, "Should be 2 Foos now");
equal (yield db.users.where('first').equals('Foo2').count(), 4, "Should be 4 Foo2s now");
let foo2s = yield db.users.where('first').equals('Foo2').toArray();
equal (foo2s[0].last, "BarA", "BarA should be first (updated previous ID)");
equal (foo2s[1].last, "BarC", "BarC should be second (updated previous ID");
equal (foo2s[2].last, "BarB", "BarB should be third (got new key)");
Expand Down

0 comments on commit 2d42749

Please sign in to comment.