|
1 | 1 | /** |
2 | 2 | * @author Jason Dobry <jason.dobry@gmail.com> |
3 | 3 | * @file angular-data.js |
4 | | -* @version 1.3.0 - Homepage <http://angular-data.pseudobry.com/> |
| 4 | +* @version 1.4.0 - Homepage <http://angular-data.pseudobry.com/> |
5 | 5 | * @copyright (c) 2014 Jason Dobry <https://github.com/jmdobry/> |
6 | 6 | * @license MIT <https://github.com/jmdobry/angular-data/blob/master/LICENSE> |
7 | 7 | * |
|
26 | 26 | // Copyright 2014 Jason Dobry |
27 | 27 | // |
28 | 28 | // Summary of modifications: |
| 29 | +// Fixed use of "delete" keyword for IE8 compatibility |
29 | 30 | // Removed all code related to: |
30 | 31 | // - ArrayObserver |
31 | 32 | // - ArraySplice |
|
523 | 524 | var expectedRecordTypes = { |
524 | 525 | add: true, |
525 | 526 | update: true, |
526 | | - delete: true |
| 527 | + 'delete': true |
527 | 528 | }; |
528 | 529 |
|
529 | 530 | function diffObjectFromChangeRecords(object, changeRecords, oldValues) { |
@@ -2826,13 +2827,12 @@ function create(resourceName, attrs, options) { |
2826 | 2827 | } else { |
2827 | 2828 | return DS.createInstance(resourceName, attrs, options); |
2828 | 2829 | } |
2829 | | - }) |
2830 | | - .catch(function (err) { |
2831 | | - if (options.eagerInject && options.cacheResponse) { |
2832 | | - DS.eject(resourceName, injected[definition.idAttribute], { notify: false }); |
2833 | | - } |
2834 | | - return DS.$q.reject(err); |
2835 | | - }); |
| 2830 | + })['catch'](function (err) { |
| 2831 | + if (options.eagerInject && options.cacheResponse) { |
| 2832 | + DS.eject(resourceName, injected[definition.idAttribute], { notify: false }); |
| 2833 | + } |
| 2834 | + return DS.$q.reject(err); |
| 2835 | + }); |
2836 | 2836 | } |
2837 | 2837 | } catch (err) { |
2838 | 2838 | deferred.reject(err); |
@@ -2939,12 +2939,12 @@ function destroy(resourceName, id, options) { |
2939 | 2939 | } |
2940 | 2940 | DS.eject(resourceName, id); |
2941 | 2941 | return id; |
2942 | | - }).catch(function (err) { |
2943 | | - if (options.eagerEject && item) { |
2944 | | - DS.inject(resourceName, item); |
2945 | | - } |
2946 | | - return DS.$q.reject(err); |
2947 | | - }); |
| 2942 | + })['catch'](function (err) { |
| 2943 | + if (options.eagerEject && item) { |
| 2944 | + DS.inject(resourceName, item); |
| 2945 | + } |
| 2946 | + return DS.$q.reject(err); |
| 2947 | + }); |
2948 | 2948 | } catch (err) { |
2949 | 2949 | deferred.reject(err); |
2950 | 2950 | return deferred.promise; |
@@ -5369,7 +5369,7 @@ function createInstance(resourceName, attrs, options) { |
5369 | 5369 | var item; |
5370 | 5370 |
|
5371 | 5371 | if (options.useClass) { |
5372 | | - var Func = definition[definition.class]; |
| 5372 | + var Func = definition[definition['class']]; |
5373 | 5373 | item = new Func(); |
5374 | 5374 | } else { |
5375 | 5375 | item = {}; |
@@ -5398,7 +5398,17 @@ var instanceMethods = [ |
5398 | 5398 | 'save', |
5399 | 5399 | 'update', |
5400 | 5400 | 'destroy', |
5401 | | - 'refresh' |
| 5401 | + 'refresh', |
| 5402 | + 'loadRelations', |
| 5403 | + 'changeHistory', |
| 5404 | + 'changes', |
| 5405 | + 'hasChanges', |
| 5406 | + 'lastModified', |
| 5407 | + 'lastSaved', |
| 5408 | + 'link', |
| 5409 | + 'linkInverse', |
| 5410 | + 'previous', |
| 5411 | + 'unlinkInverse' |
5402 | 5412 | ]; |
5403 | 5413 |
|
5404 | 5414 | var methodsToProxy = [ |
@@ -5620,13 +5630,13 @@ function defineResource(definition) { |
5620 | 5630 | }); |
5621 | 5631 |
|
5622 | 5632 | // Create the wrapper class for the new resource |
5623 | | - def.class = DSUtils.pascalCase(defName); |
5624 | | - eval('function ' + def.class + '() {}'); |
5625 | | - def[def.class] = eval(def.class); |
| 5633 | + def['class'] = DSUtils.pascalCase(defName); |
| 5634 | + eval('function ' + def['class'] + '() {}'); |
| 5635 | + def[def['class']] = eval(def['class']); |
5626 | 5636 |
|
5627 | 5637 | // Apply developer-defined methods |
5628 | 5638 | if (def.methods) { |
5629 | | - DSUtils.deepMixIn(def[def.class].prototype, def.methods); |
| 5639 | + DSUtils.deepMixIn(def[def['class']].prototype, def.methods); |
5630 | 5640 | } |
5631 | 5641 |
|
5632 | 5642 | // Prepare for computed properties |
@@ -5658,13 +5668,13 @@ function defineResource(definition) { |
5658 | 5668 | }); |
5659 | 5669 | }); |
5660 | 5670 |
|
5661 | | - def[def.class].prototype.DSCompute = function () { |
| 5671 | + def[def['class']].prototype.DSCompute = function () { |
5662 | 5672 | return DS.compute(def.name, this); |
5663 | 5673 | }; |
5664 | 5674 | } |
5665 | 5675 |
|
5666 | 5676 | DSUtils.forEach(instanceMethods, function (name) { |
5667 | | - def[def.class].prototype['DS' + DSUtils.pascalCase(name)] = function () { |
| 5677 | + def[def['class']].prototype['DS' + DSUtils.pascalCase(name)] = function () { |
5668 | 5678 | var args = Array.prototype.slice.call(arguments); |
5669 | 5679 | args.unshift(this[def.idAttribute]); |
5670 | 5680 | args.unshift(def.name); |
@@ -6581,8 +6591,8 @@ function _inject(definition, resource, attrs, options) { |
6581 | 6591 |
|
6582 | 6592 | if (definition.idAttribute in changed) { |
6583 | 6593 | $log.error('Doh! You just changed the primary key of an object! ' + |
6584 | | - 'I don\'t know how to handle this yet, so your data for the "' + definition.name + |
6585 | | - '" resource is now in an undefined (probably broken) state.'); |
| 6594 | + 'I don\'t know how to handle this yet, so your data for the "' + definition.name + |
| 6595 | + '" resource is now in an undefined (probably broken) state.'); |
6586 | 6596 | } |
6587 | 6597 | } |
6588 | 6598 |
|
@@ -6616,10 +6626,10 @@ function _inject(definition, resource, attrs, options) { |
6616 | 6626 |
|
6617 | 6627 | if (!item) { |
6618 | 6628 | if (options.useClass) { |
6619 | | - if (attrs instanceof definition[definition.class]) { |
| 6629 | + if (attrs instanceof definition[definition['class']]) { |
6620 | 6630 | item = attrs; |
6621 | 6631 | } else { |
6622 | | - item = new definition[definition.class](); |
| 6632 | + item = new definition[definition['class']](); |
6623 | 6633 | } |
6624 | 6634 | } else { |
6625 | 6635 | item = {}; |
@@ -7434,7 +7444,7 @@ function IllegalArgumentError(message) { |
7434 | 7444 | this.message = message || 'Illegal Argument!'; |
7435 | 7445 | } |
7436 | 7446 |
|
7437 | | -IllegalArgumentError.prototype = Object.create(Error.prototype); |
| 7447 | +IllegalArgumentError.prototype = new Error(); |
7438 | 7448 | IllegalArgumentError.prototype.constructor = IllegalArgumentError; |
7439 | 7449 |
|
7440 | 7450 | /** |
@@ -7470,7 +7480,7 @@ function RuntimeError(message) { |
7470 | 7480 | this.message = message || 'RuntimeError Error!'; |
7471 | 7481 | } |
7472 | 7482 |
|
7473 | | -RuntimeError.prototype = Object.create(Error.prototype); |
| 7483 | +RuntimeError.prototype = new Error(); |
7474 | 7484 | RuntimeError.prototype.constructor = RuntimeError; |
7475 | 7485 |
|
7476 | 7486 | /** |
@@ -7506,7 +7516,7 @@ function NonexistentResourceError(resourceName) { |
7506 | 7516 | this.message = (resourceName || '') + ' is not a registered resource!'; |
7507 | 7517 | } |
7508 | 7518 |
|
7509 | | -NonexistentResourceError.prototype = Object.create(Error.prototype); |
| 7519 | +NonexistentResourceError.prototype = new Error(); |
7510 | 7520 | NonexistentResourceError.prototype.constructor = NonexistentResourceError; |
7511 | 7521 |
|
7512 | 7522 | /** |
|
0 commit comments