ember-resource 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +1 -1
- data/lib/ember-resource/version.rb +1 -1
- data/vendor/assets/javascripts/ember-resource.js +56 -38
- metadata +3 -3
data/README.md
CHANGED
@@ -4,7 +4,7 @@ A version of the ember-resource javascript library packaged for the asset pipeli
|
|
4
4
|
|
5
5
|
Original project is https://github.com/staugaard/ember-resource
|
6
6
|
|
7
|
-
Version taken at commit
|
7
|
+
Version taken at commit c34fa3bfadfe82481f5a97329734ed4394bb1dc0
|
8
8
|
|
9
9
|
|
10
10
|
## Installation
|
@@ -1,7 +1,5 @@
|
|
1
1
|
(function(undefined) {
|
2
2
|
|
3
|
-
window.Ember = window.Ember || window.SC;
|
4
|
-
|
5
3
|
var expandSchema, expandSchemaItem, createSchemaProperties,
|
6
4
|
mergeSchemas;
|
7
5
|
|
@@ -13,13 +11,6 @@
|
|
13
11
|
return obj === Object(obj);
|
14
12
|
}
|
15
13
|
|
16
|
-
function K() {};
|
17
|
-
|
18
|
-
Ember.Resource = Ember.Object.extend({
|
19
|
-
resourcePropertyWillChange: K,
|
20
|
-
resourcePropertyDidChange: K
|
21
|
-
});
|
22
|
-
|
23
14
|
Ember.Resource.deepSet = function(obj, path, value) {
|
24
15
|
if (Ember.typeOf(path) === 'string') {
|
25
16
|
Ember.Resource.deepSet(obj, path.split('.'), value);
|
@@ -561,25 +552,23 @@
|
|
561
552
|
// resource; // another way to reference the resource object
|
562
553
|
// }
|
563
554
|
//
|
564
|
-
var
|
555
|
+
var errorHandlerWithContext = function(errorHandler, context) {
|
565
556
|
return function() {
|
566
557
|
var args = Array.prototype.slice.call(arguments, 0);
|
567
|
-
args.push(
|
568
|
-
errorHandler.apply(
|
558
|
+
args.push(context);
|
559
|
+
errorHandler.apply(context, args);
|
569
560
|
};
|
570
561
|
};
|
571
562
|
|
572
563
|
Ember.Resource.ajax = function(options) {
|
564
|
+
if(window.stopHere) { debugger }
|
573
565
|
options.dataType = options.dataType || 'json';
|
574
566
|
options.type = options.type || 'GET';
|
575
567
|
|
576
|
-
if
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
} else {
|
581
|
-
options.error = Ember.Resource.errorHandler;
|
582
|
-
}
|
568
|
+
if(options.error) {
|
569
|
+
options.error = errorHandlerWithContext(options.error, options);
|
570
|
+
} else if(Em.Resource.errorHandler) {
|
571
|
+
options.error = errorHandlerWithContext(Ember.Resource.errorHandler, options);
|
583
572
|
}
|
584
573
|
|
585
574
|
return $.ajax(options);
|
@@ -754,6 +743,13 @@
|
|
754
743
|
willSave: function() {},
|
755
744
|
didSave: function() {},
|
756
745
|
|
746
|
+
fetched: function() {
|
747
|
+
if(!this._fetchDfd) {
|
748
|
+
this._fetchDfd = $.Deferred();
|
749
|
+
}
|
750
|
+
return this._fetchDfd;
|
751
|
+
},
|
752
|
+
|
757
753
|
fetch: function() {
|
758
754
|
if (!Ember.get(this, 'isFetchable')) return $.when();
|
759
755
|
|
@@ -770,6 +766,8 @@
|
|
770
766
|
|
771
767
|
this.deferedFetch = Ember.Resource.ajax({
|
772
768
|
url: url,
|
769
|
+
resource: this,
|
770
|
+
operation: 'read',
|
773
771
|
success: function(json) {
|
774
772
|
self.updateWithApiData(json);
|
775
773
|
}
|
@@ -778,6 +776,7 @@
|
|
778
776
|
this.deferedFetch.always(function() {
|
779
777
|
self.didFetch.call(self);
|
780
778
|
Ember.sendEvent(self, 'didFetch');
|
779
|
+
self.fetched().resolve();
|
781
780
|
});
|
782
781
|
|
783
782
|
return this.deferedFetch;
|
@@ -825,9 +824,11 @@
|
|
825
824
|
if (Ember.get(this, 'isNew')) {
|
826
825
|
ajaxOptions.type = 'POST';
|
827
826
|
ajaxOptions.url = this.constructor.resourceURL();
|
827
|
+
ajaxOptions.operation = 'create';
|
828
828
|
} else {
|
829
829
|
ajaxOptions.type = 'PUT';
|
830
830
|
ajaxOptions.url = this.resourceURL();
|
831
|
+
ajaxOptions.operation = 'update';
|
831
832
|
}
|
832
833
|
|
833
834
|
var self = this;
|
@@ -864,6 +865,8 @@
|
|
864
865
|
Ember.set(this, 'resourceState', Ember.Resource.Lifecycle.DESTROYING);
|
865
866
|
return Ember.Resource.ajax({
|
866
867
|
type: 'DELETE',
|
868
|
+
resource: this,
|
869
|
+
operation: 'destroy',
|
867
870
|
url: this.resourceURL(),
|
868
871
|
resource: this
|
869
872
|
}).done(function() {
|
@@ -939,15 +942,16 @@
|
|
939
942
|
|
940
943
|
if (klass === this) {
|
941
944
|
var instance;
|
942
|
-
this.identityMap = this.identityMap ||
|
945
|
+
this.identityMap = this.identityMap || new Ember.Resource.IdentityMap(this.identityMapLimit);
|
943
946
|
|
944
947
|
var id = data.id || options.id;
|
945
948
|
if (id && !options.skipIdentityMap) {
|
946
949
|
id = id.toString();
|
947
|
-
instance = this.identityMap
|
950
|
+
instance = this.identityMap.get(id);
|
948
951
|
|
949
952
|
if (!instance) {
|
950
|
-
|
953
|
+
instance = this._super.call(this, { data: data });
|
954
|
+
this.identityMap.put(id, instance);
|
951
955
|
} else {
|
952
956
|
instance.updateWithApiData(data);
|
953
957
|
}
|
@@ -1023,6 +1027,10 @@
|
|
1023
1027
|
classOptions.parse = options.parse;
|
1024
1028
|
}
|
1025
1029
|
|
1030
|
+
if (options.identityMapLimit) {
|
1031
|
+
classOptions.identityMapLimit = options.identityMapLimit;
|
1032
|
+
}
|
1033
|
+
|
1026
1034
|
klass.reopenClass(classOptions);
|
1027
1035
|
|
1028
1036
|
return klass;
|
@@ -1063,24 +1071,31 @@
|
|
1063
1071
|
Ember.ResourceCollection = Ember.ArrayProxy.extend({
|
1064
1072
|
isEmberResourceCollection: true,
|
1065
1073
|
type: Ember.required(),
|
1074
|
+
|
1075
|
+
fetched: function() {
|
1076
|
+
if(!this._fetchDfd) {
|
1077
|
+
this._fetchDfd = $.Deferred();
|
1078
|
+
}
|
1079
|
+
return this._fetchDfd;
|
1080
|
+
},
|
1081
|
+
|
1066
1082
|
fetch: function() {
|
1067
|
-
if (!Ember.get(this, 'isFetchable')) return $.when();
|
1083
|
+
if (!Ember.get(this, 'isFetchable') || Ember.get(this, 'prePopulated')) return $.when();
|
1068
1084
|
|
1069
|
-
|
1070
|
-
var self = this;
|
1085
|
+
var self = this;
|
1071
1086
|
|
1072
|
-
|
1087
|
+
if (this.deferedFetch && !Ember.get(this, 'isExpired')) return this.deferedFetch;
|
1073
1088
|
|
1074
|
-
|
1089
|
+
Ember.sendEvent(self, 'willFetch');
|
1075
1090
|
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1091
|
+
this.deferedFetch = this._fetch(function(json) {
|
1092
|
+
Ember.set(self, 'content', self.parse(json));
|
1093
|
+
});
|
1079
1094
|
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
}
|
1095
|
+
this.deferedFetch.always(function() {
|
1096
|
+
Ember.sendEvent(self, 'didFetch');
|
1097
|
+
self.fetched().resolve();
|
1098
|
+
});
|
1084
1099
|
return this.deferedFetch;
|
1085
1100
|
},
|
1086
1101
|
_resolveType: function() {
|
@@ -1093,6 +1108,8 @@
|
|
1093
1108
|
this._resolveType();
|
1094
1109
|
return Ember.Resource.ajax({
|
1095
1110
|
url: this.resolveUrl(),
|
1111
|
+
resource: this,
|
1112
|
+
operation: 'read',
|
1096
1113
|
success: callback
|
1097
1114
|
});
|
1098
1115
|
},
|
@@ -1131,7 +1148,7 @@
|
|
1131
1148
|
}.property().cacheable(),
|
1132
1149
|
|
1133
1150
|
autoFetchOnExpiry: function() {
|
1134
|
-
if (Ember.get(this, 'isExpired') && Ember.get(this, 'hasArrayObservers')) {
|
1151
|
+
if (Ember.get(this, 'isAutoFetchable') && Ember.get(this, 'isExpired') && Ember.get(this, 'hasArrayObservers')) {
|
1135
1152
|
this.fetch();
|
1136
1153
|
}
|
1137
1154
|
}.observes('isExpired', 'hasArrayObservers'),
|
@@ -1145,6 +1162,7 @@
|
|
1145
1162
|
|
1146
1163
|
Ember.ResourceCollection.reopenClass({
|
1147
1164
|
isEmberResourceCollection: true,
|
1165
|
+
identityMapLimit: Ember.Resource.IdentityMap.DEFAULT_IDENTITY_MAP_LIMIT * 5,
|
1148
1166
|
create: function(options) {
|
1149
1167
|
options = options || {};
|
1150
1168
|
var content = options.content;
|
@@ -1155,10 +1173,10 @@
|
|
1155
1173
|
var instance;
|
1156
1174
|
|
1157
1175
|
if (!options.prePopulated && options.url) {
|
1158
|
-
this.identityMap = this.identityMap ||
|
1176
|
+
this.identityMap = this.identityMap || new Ember.Resource.IdentityMap(this.identityMapLimit);
|
1159
1177
|
var identity = [options.type, options.url];
|
1160
|
-
instance = this.identityMap
|
1161
|
-
this.identityMap
|
1178
|
+
instance = this.identityMap.get(identity) || this._super.call(this, options);
|
1179
|
+
this.identityMap.put(identity, instance);
|
1162
1180
|
}
|
1163
1181
|
|
1164
1182
|
if (!instance) {
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ember-resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-04-19 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: Ember resource asset pipeline
|
16
16
|
email:
|
@@ -48,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
48
|
version: '0'
|
49
49
|
requirements: []
|
50
50
|
rubyforge_project:
|
51
|
-
rubygems_version: 1.8.
|
51
|
+
rubygems_version: 1.8.21
|
52
52
|
signing_key:
|
53
53
|
specification_version: 3
|
54
54
|
summary: Ember resource asset pipeline
|