|
14 | 14 | (function (global, publish, undefined) {
|
15 | 15 |
|
16 | 16 | "use strict";
|
| 17 | + |
| 18 | + var isArray = Array.isArray; |
| 19 | + var keys = Object.keys; |
| 20 | + var _slice = [].slice; |
17 | 21 |
|
18 | 22 | function extend(obj, extension) {
|
19 | 23 | if (typeof extension !== 'object') extension = extension(); // Allow to supply a function returning the extension. Useful for simplifying private scopes.
|
20 |
| - Object.keys(extension).forEach(function (key) { |
| 24 | + keys(extension).forEach(function (key) { |
21 | 25 | obj[key] = extension[key];
|
22 | 26 | });
|
23 | 27 | return obj;
|
|
37 | 41 | };
|
38 | 42 | }
|
39 | 43 |
|
| 44 | + function slice(args, start, end) { |
| 45 | + return _slice.call(args, start, end); |
| 46 | + } |
| 47 | + |
40 | 48 | function override(origFunc, overridedFactory) {
|
41 | 49 | return overridedFactory(origFunc);
|
42 | 50 | }
|
|
146 | 154 | // Update API
|
147 | 155 | globalSchema = db._dbSchema = dbschema;
|
148 | 156 | removeTablesApi([allTables, db, notInTransFallbackTables]);
|
149 |
| - setApiOnPlace([notInTransFallbackTables], tableNotInTransaction, Object.keys(dbschema), READWRITE, dbschema); |
150 |
| - setApiOnPlace([allTables, db, this._cfg.tables], db._transPromiseFactory, Object.keys(dbschema), READWRITE, dbschema, true); |
151 |
| - dbStoreNames = Object.keys(dbschema); |
| 157 | + setApiOnPlace([notInTransFallbackTables], tableNotInTransaction, keys(dbschema), READWRITE, dbschema); |
| 158 | + setApiOnPlace([allTables, db, this._cfg.tables], db._transPromiseFactory, keys(dbschema), READWRITE, dbschema, true); |
| 159 | + dbStoreNames = keys(dbschema); |
152 | 160 | return this;
|
153 | 161 | },
|
154 | 162 | upgrade: function (upgradeFunction) {
|
155 | 163 | /// <param name="upgradeFunction" optional="true">Function that performs upgrading actions.</param>
|
156 | 164 | var self = this;
|
157 | 165 | fakeAutoComplete(function () {
|
158 |
| - upgradeFunction(db._createTransaction(READWRITE, Object.keys(self._cfg.dbschema), self._cfg.dbschema));// BUGBUG: No code completion for prev version's tables wont appear. |
| 166 | + upgradeFunction(db._createTransaction(READWRITE, keys(self._cfg.dbschema), self._cfg.dbschema));// BUGBUG: No code completion for prev version's tables wont appear. |
159 | 167 | });
|
160 | 168 | this._cfg.contentUpgrade = upgradeFunction;
|
161 | 169 | return this;
|
162 | 170 | },
|
163 | 171 | _parseStoresSpec: function (stores, outSchema) {
|
164 |
| - Object.keys(stores).forEach(function (tableName) { |
| 172 | + keys(stores).forEach(function (tableName) { |
165 | 173 | if (stores[tableName] !== null) {
|
166 | 174 | var instanceTemplate = {};
|
167 | 175 | var indexes = parseIndexSyntax(stores[tableName]);
|
|
183 | 191 | if (oldVersion === 0) {
|
184 | 192 | //globalSchema = versions[versions.length - 1]._cfg.dbschema;
|
185 | 193 | // Create tables:
|
186 |
| - Object.keys(globalSchema).forEach(function (tableName) { |
| 194 | + keys(globalSchema).forEach(function (tableName) { |
187 | 195 | createTable(idbtrans, tableName, globalSchema[tableName].primKey, globalSchema[tableName].indexes);
|
188 | 196 | });
|
189 | 197 | // Populate data
|
|
250 | 258 | if (version._cfg.contentUpgrade) {
|
251 | 259 | queue.push(function (idbtrans, cb) {
|
252 | 260 | anyContentUpgraderHasRun = true;
|
253 |
| - var t = db._createTransaction(READWRITE, [].slice.call(idbtrans.db.objectStoreNames, 0), newSchema); |
| 261 | + var t = db._createTransaction(READWRITE, slice(idbtrans.db.objectStoreNames), newSchema); |
254 | 262 | t.idbtrans = idbtrans;
|
255 | 263 | var uncompletedRequests = 0;
|
256 | 264 | t._promise = override(t._promise, function (orig_promise) {
|
|
358 | 366 | }
|
359 | 367 |
|
360 | 368 | function createMissingTables(newSchema, idbtrans) {
|
361 |
| - Object.keys(newSchema).forEach(function (tableName) { |
| 369 | + keys(newSchema).forEach(function (tableName) { |
362 | 370 | if (!idbtrans.db.objectStoreNames.contains(tableName)) {
|
363 | 371 | createTable(idbtrans, tableName, newSchema[tableName].primKey, newSchema[tableName].indexes);
|
364 | 372 | }
|
|
652 | 660 | Object.defineProperty(this, "tables", {
|
653 | 661 | get: function () {
|
654 | 662 | /// <returns type="Array" elementType="WriteableTable" />
|
655 |
| - return Object.keys(allTables).map(function (name) { return allTables[name]; }); |
| 663 | + return keys(allTables).map(function (name) { return allTables[name]; }); |
656 | 664 | }
|
657 | 665 | });
|
658 | 666 |
|
|
693 | 701 | /// <param name="scopeFunc" type="Function">Function to execute with transaction</param>
|
694 | 702 |
|
695 | 703 | // Let table arguments be all arguments between mode and last argument.
|
696 |
| - tableInstances = [].slice.call(arguments, 1, arguments.length - 1); |
| 704 | + tableInstances = slice(arguments, 1, arguments.length - 1); |
697 | 705 | // Let scopeFunc be the last argument
|
698 | 706 | scopeFunc = arguments[arguments.length - 1];
|
699 | 707 | var parentTransaction = Promise.PSD && Promise.PSD.trans;
|
|
704 | 712 | //
|
705 | 713 | // Get storeNames from arguments. Either through given table instances, or through given table names.
|
706 | 714 | //
|
707 |
| - var tables = Array.isArray(tableInstances[0]) ? tableInstances.reduce(function (a, b) { return a.concat(b); }) : tableInstances; |
| 715 | + var tables = isArray(tableInstances[0]) ? tableInstances.reduce(function (a, b) { return a.concat(b); }) : tableInstances; |
708 | 716 | var error = null;
|
709 | 717 | var storeNames = tables.map(function (tableInstance) {
|
710 | 718 | if (typeof tableInstance === "string") {
|
|
1154 | 1162 | },
|
1155 | 1163 |
|
1156 | 1164 | update: function (keyOrObject, modifications) {
|
1157 |
| - if (typeof modifications !== 'object' || Array.isArray(modifications)) throw new Error("db.update(keyOrObject, modifications). modifications must be an object."); |
1158 |
| - if (typeof keyOrObject === 'object' && !Array.isArray(keyOrObject)) { |
| 1165 | + if (typeof modifications !== 'object' || isArray(modifications)) throw new Error("db.update(keyOrObject, modifications). modifications must be an object."); |
| 1166 | + if (typeof keyOrObject === 'object' && !isArray(keyOrObject)) { |
1159 | 1167 | // object to modify. Also modify given object with the modifications:
|
1160 |
| - Object.keys(modifications).forEach(function (keyPath) { |
| 1168 | + keys(modifications).forEach(function (keyPath) { |
1161 | 1169 | setByKeyPath(keyOrObject, keyPath, modifications[keyPath]);
|
1162 | 1170 | });
|
1163 | 1171 | var key = getByKeyPath(keyOrObject, this.schema.primKey.keyPath);
|
|
1374 | 1382 | }
|
1375 | 1383 |
|
1376 | 1384 | function getSetArgs(args) {
|
1377 |
| - return Array.prototype.slice.call(args.length === 1 && Array.isArray(args[0]) ? args[0] : args); |
| 1385 | + return slice(args.length === 1 && isArray(args[0]) ? args[0] : args); |
1378 | 1386 | }
|
1379 | 1387 |
|
1380 | 1388 | function upperFactory(dir) {
|
|
2000 | 2008 | if (additionalChanges) {
|
2001 | 2009 | // Hook want to apply additional modifications. Make sure to fullfill the will of the hook.
|
2002 | 2010 | item = this.value;
|
2003 |
| - Object.keys(additionalChanges).forEach(function (keyPath) { |
| 2011 | + keys(additionalChanges).forEach(function (keyPath) { |
2004 | 2012 | setByKeyPath(item, keyPath, additionalChanges[keyPath]); // Adding {keyPath: undefined} means that the keyPath should be deleted. Handled by setByKeyPath
|
2005 | 2013 | });
|
2006 | 2014 | }
|
|
2009 | 2017 | }
|
2010 | 2018 | } else if (updatingHook === nop) {
|
2011 | 2019 | // changes is a set of {keyPath: value} and no one is listening to the updating hook.
|
2012 |
| - var keyPaths = Object.keys(changes); |
| 2020 | + var keyPaths = keys(changes); |
2013 | 2021 | var numKeys = keyPaths.length;
|
2014 | 2022 | modifyer = function (item) {
|
2015 | 2023 | var anythingModified = false;
|
|
2031 | 2039 | var anythingModified = false;
|
2032 | 2040 | var additionalChanges = updatingHook.call(this, changes, this.primKey, deepClone(item), trans);
|
2033 | 2041 | if (additionalChanges) extend(changes, additionalChanges);
|
2034 |
| - Object.keys(changes).forEach(function (keyPath) { |
| 2042 | + keys(changes).forEach(function (keyPath) { |
2035 | 2043 | var val = changes[keyPath];
|
2036 | 2044 | if (getByKeyPath(item, keyPath) !== val) {
|
2037 | 2045 | setByKeyPath(item, keyPath, val);
|
|
2194 | 2202 | index.indexOf('&') !== -1,
|
2195 | 2203 | index.indexOf('*') !== -1,
|
2196 | 2204 | index.indexOf("++") !== -1,
|
2197 |
| - Array.isArray(keyPath), |
| 2205 | + isArray(keyPath), |
2198 | 2206 | keyPath.indexOf('.') !== -1
|
2199 | 2207 | ));
|
2200 | 2208 | });
|
|
2234 | 2242 | function readGlobalSchema() {
|
2235 | 2243 | db.verno = idbdb.version / 10;
|
2236 | 2244 | db._dbSchema = globalSchema = {};
|
2237 |
| - dbStoreNames = [].slice.call(idbdb.objectStoreNames, 0); |
| 2245 | + dbStoreNames = slice(idbdb.objectStoreNames, 0); |
2238 | 2246 | if (dbStoreNames.length === 0) return; // Database contains no stores.
|
2239 | 2247 | var trans = idbdb.transaction(safariMultiStoreFix(dbStoreNames), 'readonly');
|
2240 | 2248 | dbStoreNames.forEach(function (storeName) {
|
|
2252 | 2260 | }
|
2253 | 2261 | globalSchema[storeName] = new TableSchema(storeName, primKey, indexes, {});
|
2254 | 2262 | });
|
2255 |
| - setApiOnPlace([allTables], db._transPromiseFactory, Object.keys(globalSchema), READWRITE, globalSchema); |
| 2263 | + setApiOnPlace([allTables], db._transPromiseFactory, keys(globalSchema), READWRITE, globalSchema); |
2256 | 2264 | }
|
2257 | 2265 |
|
2258 | 2266 | function adjustToExistingIndexNames(schema, idbtrans) {
|
|
2268 | 2276 | for (var j = 0; j < store.indexNames.length; ++j) {
|
2269 | 2277 | var indexName = store.indexNames[j];
|
2270 | 2278 | var keyPath = store.index(indexName).keyPath;
|
2271 |
| - var dexieName = typeof keyPath === 'string' ? keyPath : "[" + [].slice.call(keyPath).join('+') + "]"; |
| 2279 | + var dexieName = typeof keyPath === 'string' ? keyPath : "[" + slice(keyPath).join('+') + "]"; |
2272 | 2280 | if (schema[storeName]) {
|
2273 | 2281 | var indexSpec = schema[storeName].idxByName[dexieName];
|
2274 | 2282 | if (indexSpec) indexSpec.name = indexName;
|
|
2315 | 2323 | var Promise = (function () {
|
2316 | 2324 |
|
2317 | 2325 | // The use of asap in handle() is remarked because we must NOT use setTimeout(fn,0) because it causes premature commit of indexedDB transactions - which is according to indexedDB specification.
|
2318 |
| - var _slice = [].slice; |
2319 |
| - var _asap = typeof setImmediate === 'undefined' ? function(fn, arg1, arg2, argN) { |
2320 |
| - var args = arguments; |
2321 |
| - setTimeout(function() { fn.apply(global, _slice.call(args, 1)); }, 0); // If not FF13 and earlier failed, we could use this call here instead: setTimeout.call(this, [fn, 0].concat(arguments)); |
2322 |
| - } : setImmediate; // IE10+ and node. |
| 2326 | + var _asap = global.setImmediate || function(fn) { |
| 2327 | + var args = slice(arguments, 1); |
| 2328 | + |
| 2329 | + // If not FF13 and earlier failed, we could use this call here instead: setTimeout.call(this, [fn, 0].concat(arguments)); |
| 2330 | + setTimeout(function() { |
| 2331 | + fn.apply(global, args); |
| 2332 | + }, 0); |
| 2333 | + } |
2323 | 2334 |
|
2324 | 2335 | doFakeAutoComplete(function () {
|
2325 | 2336 | // Simplify the job for VS Intellisense. This piece of code is one of the keys to the new marvellous intellisense support in Dexie.
|
2326 | 2337 | _asap = asap = enqueueImmediate = function(fn) {
|
2327 |
| - var args = arguments; setTimeout(function() { fn.apply(global, _slice.call(args, 1)); }, 0); |
| 2338 | + var args = arguments; setTimeout(function() { fn.apply(global, slice(args, 1)); }, 0); |
2328 | 2339 | };
|
2329 | 2340 | });
|
2330 | 2341 |
|
|
2334 | 2345 | var operationsQueue = [];
|
2335 | 2346 | var tickFinalizers = [];
|
2336 | 2347 | function enqueueImmediate(fn, args) {
|
2337 |
| - operationsQueue.push([fn, _slice.call(arguments, 1)]); |
| 2348 | + operationsQueue.push([fn, slice(arguments, 1)]); |
2338 | 2349 | }
|
2339 | 2350 |
|
2340 | 2351 | function executeOperationsQueue() {
|
|
2530 | 2541 | Promise.on = events(null, "error");
|
2531 | 2542 |
|
2532 | 2543 | Promise.all = function () {
|
2533 |
| - var args = Array.prototype.slice.call(arguments.length === 1 && Array.isArray(arguments[0]) ? arguments[0] : arguments); |
| 2544 | + var args = slice(arguments.length === 1 && isArray(arguments[0]) ? arguments[0] : arguments); |
2534 | 2545 |
|
2535 | 2546 | return new Promise(function (resolve, reject) {
|
2536 | 2547 | if (args.length === 0) return resolve([]);
|
|
2757 | 2768 | var rv = function (eventName, subscriber) {
|
2758 | 2769 | if (subscriber) {
|
2759 | 2770 | // Subscribe
|
2760 |
| - var args = [].slice.call(arguments, 1); |
| 2771 | + var args = slice(arguments, 1); |
2761 | 2772 | var ev = evs[eventName];
|
2762 | 2773 | ev.subscribe.apply(ev, args);
|
2763 | 2774 | return ctx;
|
|
2769 | 2780 | rv.addEventType = add;
|
2770 | 2781 |
|
2771 | 2782 | function add(eventName, chainFunction, defaultFunction) {
|
2772 |
| - if (Array.isArray(eventName)) return addEventGroup(eventName); |
| 2783 | + if (isArray(eventName)) return addEventGroup(eventName); |
2773 | 2784 | if (typeof eventName === 'object') return addConfiguredEvents(eventName);
|
2774 | 2785 | if (!chainFunction) chainFunction = stoppableEventChain;
|
2775 | 2786 | if (!defaultFunction) defaultFunction = nop;
|
|
2792 | 2803 |
|
2793 | 2804 | function addConfiguredEvents(cfg) {
|
2794 | 2805 | // events(this, {reading: [functionChain, nop]});
|
2795 |
| - Object.keys(cfg).forEach(function (eventName) { |
| 2806 | + keys(cfg).forEach(function (eventName) { |
2796 | 2807 | var args = cfg[eventName];
|
2797 |
| - if (Array.isArray(args)) { |
| 2808 | + if (isArray(args)) { |
2798 | 2809 | add(eventName, cfg[eventName][0], cfg[eventName][1]);
|
2799 | 2810 | } else if (args === 'asap') {
|
2800 | 2811 | // Rather than approaching event subscription using a functional approach, we here do it in a for-loop where subscriber is executed in its own stack
|
|
2935 | 2946 | function deepClone(any) {
|
2936 | 2947 | if (!any || typeof any !== 'object') return any;
|
2937 | 2948 | var rv;
|
2938 |
| - if (Array.isArray(any)) { |
| 2949 | + if (isArray(any)) { |
2939 | 2950 | rv = [];
|
2940 | 2951 | for (var i = 0, l = any.length; i < l; ++i) {
|
2941 | 2952 | rv.push(deepClone(any[i]));
|
|
2975 | 2986 | function parseType(type) {
|
2976 | 2987 | if (typeof type === 'function') {
|
2977 | 2988 | return new type();
|
2978 |
| - } else if (Array.isArray(type)) { |
| 2989 | + } else if (isArray(type)) { |
2979 | 2990 | return [parseType(type[0])];
|
2980 | 2991 | } else if (type && typeof type === 'object') {
|
2981 | 2992 | var rv = {};
|
|
2987 | 2998 | }
|
2988 | 2999 |
|
2989 | 3000 | function applyStructure(obj, structure) {
|
2990 |
| - Object.keys(structure).forEach(function (member) { |
| 3001 | + keys(structure).forEach(function (member) { |
2991 | 3002 | var value = parseType(structure[member]);
|
2992 | 3003 | obj[member] = value;
|
2993 | 3004 | });
|
|
3143 | 3154 | if (getDatabaseNames) { // In case getDatabaseNames() becomes standard, let's prepare to support it:
|
3144 | 3155 | var req = getDatabaseNames();
|
3145 | 3156 | req.onsuccess = function (event) {
|
3146 |
| - resolve([].slice.call(event.target.result, 0)); // Converst DOMStringList to Array<String> |
| 3157 | + resolve(slice(event.target.result, 0)); // Converst DOMStringList to Array<String> |
3147 | 3158 | };
|
3148 | 3159 | req.onerror = eventRejectHandler(reject);
|
3149 | 3160 | } else {
|
|
3302 | 3313 |
|
3303 | 3314 | // Vanilla HTML and WebWorkers:
|
3304 | 3315 | : [self || window, function (name, value) { (self || window)[name] = value; }]);
|
3305 |
| - |
|
0 commit comments