Permalink
Browse files

Merge branch 'master' into pagination

Conflicts:
	server/vendor/monarch/client/lib/monarch/model/relations/ordering.js
	server/vendor/monarch/client/lib/monarch/model/relations/relation.js
  • Loading branch information...
nathansobo committed Jan 4, 2011
2 parents ce7f12b + 8b925b0 commit b5f1fd5310b5ead06fcea39d0ccbfca8e673b23a
Showing with 1,633 additions and 2,310 deletions.
  1. +1 −0 lib/monarch.js
  2. +0 −1 lib/monarch/http.js
  3. +24 −0 lib/monarch/http/command.js
  4. +0 −56 lib/monarch/http/command_batch.js
  5. +2 −2 lib/monarch/http/create_command.js
  6. +2 −2 lib/monarch/http/destroy_command.js
  7. +13 −49 lib/monarch/http/server.js
  8. +2 −2 lib/monarch/http/update_command.js
  9. +3 −1 lib/monarch/model/column.js
  10. +6 −2 lib/monarch/model/composite_tuple.js
  11. +28 −43 lib/monarch/model/record.js
  12. +0 −1 lib/monarch/model/relations.js
  13. +38 −38 lib/monarch/model/relations/difference.js
  14. +89 −74 lib/monarch/model/relations/inner_join.js
  15. +15 −73 lib/monarch/model/relations/ordering.js
  16. +0 −75 lib/monarch/model/relations/projection.js
  17. +188 −117 lib/monarch/model/relations/relation.js
  18. +19 −38 lib/monarch/model/relations/selection.js
  19. +23 −35 lib/monarch/model/relations/table.js
  20. +40 −36 lib/monarch/model/relations/table_projection.js
  21. +41 −29 lib/monarch/model/relations/union.js
  22. +1 −1 lib/monarch/model/remote_fieldset.js
  23. +1 −2 lib/monarch/model/repository.js
  24. +2 −0 lib/monarch/model/sort_specification.js
  25. +5 −1 lib/monarch/model/tuple.js
  26. +1 −1 lib/monarch/queue.js
  27. +205 −0 lib/monarch/skip_list.js
  28. +16 −0 lib/monarch/underscore_extensions.js
  29. +1 −1 lib/monarch/view/template.js
  30. +1 −1 spec/monarch/http/ajax_future_spec.js
  31. +50 −163 spec/monarch/http/server_spec.js
  32. +14 −86 spec/monarch/model/record_spec.js
  33. +65 −166 spec/monarch/model/relations/difference_spec.js
  34. +166 −258 spec/monarch/model/relations/inner_join_spec.js
  35. +47 −27 spec/monarch/model/relations/ordering_spec.js
  36. +0 −97 spec/monarch/model/relations/projection_spec.js
  37. +2 −26 spec/monarch/model/relations/relation_spec.js
  38. +107 −291 spec/monarch/model/relations/selection_spec.js
  39. +38 −45 spec/monarch/model/relations/table_projection_spec.js
  40. +143 −278 spec/monarch/model/relations/table_spec.js
  41. +79 −53 spec/monarch/model/relations/union_spec.js
  42. +1 −1 spec/monarch/model/remote_field_spec.js
  43. +4 −4 spec/monarch/model/repository_spec.js
  44. +35 −32 spec/monarch/model/tuple_spec.js
  45. +77 −0 spec/monarch/skip_list_spec.js
  46. +2 −2 spec/monarch/view/view_spec.js
  47. +1 −2 spec/spec_helpers/fake_server.js
  48. +0 −64 spec/spec_helpers/fake_server/fake_command_batch.js
  49. +20 −16 spec/spec_helpers/fake_server/fake_mutation.js
  50. +12 −17 spec/spec_helpers/fake_server/fake_server.js
  51. +1 −1 spec/spec_helpers/fake_server_spec.js
  52. +2 −0 vendor/underscore.js
View
@@ -16,6 +16,7 @@
//= require "monarch/subscription_bundle"
//= require "monarch/future"
//= require "monarch/queue"
+//= require "monarch/skip_list"
//= require "monarch/inflection"
//= require "monarch/view"
//= require "monarch/http"
View
@@ -8,6 +8,5 @@
//= require "http/update_command"
//= require "http/destroy_command"
//= require "http/comet_client"
-//= require "http/command_batch"
})(Monarch);
@@ -1,6 +1,30 @@
(function(Monarch) {
_.constructor("Monarch.Http.Command", {
+ initialize: function(record, server) {
+ this.record = record;
+ this.server = server;
+ this.future = new Monarch.Http.AjaxFuture();
+ },
+
+ perform: function() {
+ this.server.post(Repository.originUrl + "/mutate", { operations: [this.wireRepresentation()] })
+ .onSuccess(this.hitch('handleSuccessfulResponse'))
+ .onFailure(this.hitch('handleUnsuccessfulResponse'))
+ return this.future;
+ },
+
+ handleSuccessfulResponse: function(data) {
+ this.future.updateRepositoryAndTriggerCallbacks(this.record, this.bind(function() {
+ this.complete(data.primary[0]);
+ Repository.mutate(data.secondary);
+ }));
+ },
+
+ handleUnsuccessfulResponse: function(data) {
+ this.handleFailure(data.errors);
+ this.future.triggerFailure(this.record);
+ }
});
})(Monarch);
@@ -1,56 +0,0 @@
-(function(Monarch) {
-
-_.constructor("Monarch.Http.CommandBatch", {
- initialize: function(server, commands) {
- this.server = server;
- this.commands = commands;
- },
-
- perform: function() {
- this.future = new Monarch.Http.AjaxFuture();
-
- if (this.commands.length > 0) {
- this.server.post(Repository.originUrl + "/mutate", { operations: this.wireRepresentation() })
- .onSuccess(function(responseData) {
- this.handleSuccessfulResponse(responseData);
- }, this)
- .onFailure(function(responseData) {
- this.handleUnsuccessfulResponse(responseData);
- }, this);
- } else {
- this.future.updateRepositoryAndTriggerCallbacks(null, _.identity);
- }
-
- return this.future;
- },
-
- // private
-
- wireRepresentation: function() {
- return _.map(this.commands, function(command) {
- return command.wireRepresentation();
- });
- },
-
- handleSuccessfulResponse: function(responseData) {
- this.future.updateRepositoryAndTriggerCallbacks(this.commands[0].record, _.bind(function() {
- _.each(this.commands, function(command, index) {
- command.complete(responseData.primary[index]);
- });
- Repository.mutate(responseData.secondary);
- }, this));
- },
-
- handleUnsuccessfulResponse: function(responseData) {
- _.each(this.commands, function(command, index) {
- if (index == responseData.index) {
- command.handleFailure(responseData.errors);
- this.future.triggerFailure(command.record);
- } else {
- command.handleFailure(null);
- }
- }, this);
- }
-});
-
-})(Monarch);
@@ -1,8 +1,8 @@
(function(Monarch) {
_.constructor("Monarch.Http.CreateCommand", Monarch.Http.Command, {
- initialize: function(record) {
- this.record = record;
+ initialize: function($super, record, server) {
+ $super(record, server);
this.table = this.record.table;
this.tableName = this.table.globalName;
this.fieldValues = record.dirtyWireRepresentation();
@@ -1,8 +1,8 @@
(function(Monarch) {
_.constructor("Monarch.Http.DestroyCommand", Monarch.Http.Command, {
- initialize: function(record) {
- this.record = record;
+ initialize: function($super, record, server) {
+ $super(record, server);
this.tableName = record.table.globalName;
this.id = record.id();
},
View
@@ -26,7 +26,6 @@ _.constructor("Monarch.Http.Server", {
fetch: function(relations) {
return this.get(Repository.originUrl + "/fetch", {
relations: _.map(relations, function(relation) {
- if (!relation.wireRepresentation) debugger;
return relation.wireRepresentation();
})
});
@@ -62,26 +61,16 @@ _.constructor("Monarch.Http.Server", {
});
},
- save: function() {
- var commands = _.map(this.extractDirtyRecords(arguments), function(dirtyRecord) {
- return this.buildAppropriateCommand(dirtyRecord);
- }, this);
-
+ create: function(record) {
+ return this.performCommand(new Monarch.Http.CreateCommand(record, this));
+ },
- if (_.isEmpty(commands)) {
- var saveFuture = new Monarch.Http.AjaxFuture();
- saveFuture.updateRepositoryAndTriggerCallbacks(this.firstRecord(arguments), _.identity);
- return saveFuture;
- } else {
- var batch = new Monarch.Http.CommandBatch(this, commands);
- Repository.pauseMutations();
- var saveFuture = batch.perform();
- saveFuture.onComplete(function() {
- Repository.resumeMutations();
- });
+ update: function(record) {
+ return this.performCommand(new Monarch.Http.UpdateCommand(record, this));
+ },
- return saveFuture;
- }
+ destroy: function(record) {
+ return this.performCommand(new Monarch.Http.DestroyCommand(record, this));
},
post: function(url, data) {
@@ -102,39 +91,14 @@ _.constructor("Monarch.Http.Server", {
},
// private
- newRealTimeClient: function() {
- return new Monarch.Http.CometClient(this.realTimeClientId());
+ performCommand: function(command) {
+ Repository.pauseMutations();
+ return command.perform().onComplete(Repository.hitch('resumeMutations'));
},
- extractDirtyRecords: function(recordsOrRelations) {
- var dirtyRecords = []
- _.each(recordsOrRelations, function(arg) {
- if (arg._relation_) {
- dirtyRecords.push.apply(dirtyRecords, arg.dirtyTuples());
- } else {
- if (arg.dirty()) dirtyRecords.push(arg);
- }
- });
- return dirtyRecords;
- },
-
- firstRecord: function(recordsOrRelations) {
- var first = recordsOrRelations[0];
- if (first._relation_) {
- return first.first();
- } else {
- return first;
- }
- },
- buildAppropriateCommand: function(record) {
- if (record.locallyDestroyed) {
- return new Monarch.Http.DestroyCommand(record);
- } else if (!record.isRemotelyCreated) {
- return new Monarch.Http.CreateCommand(record);
- } else {
- return new Monarch.Http.UpdateCommand(record);
- }
+ newRealTimeClient: function() {
+ return new Monarch.Http.CometClient(this.realTimeClientId());
},
request: function(type, url, data) {
@@ -1,8 +1,8 @@
(function(Monarch) {
_.constructor("Monarch.Http.UpdateCommand", Monarch.Http.Command, {
- initialize: function(record) {
- this.record = record;
+ initialize: function($super, record, server) {
+ $super(record, server);
this.version = this.record.nextPendingVersion();
this.tableName = this.record.table.globalName;
this.id = this.record.id();
@@ -4,6 +4,8 @@ _.constructor("Monarch.Model.Column", {
initialize: function(table, name, type) {
this.table = table;
this.name = name;
+ this.globalName = _.underscore(name);
+ this.qualifiedName = table.globalName + "." + this.globalName;
this.type = type;
},
@@ -43,7 +45,7 @@ _.constructor("Monarch.Model.Column", {
return {
type: "column",
table: this.table.globalName,
- name: _.underscore(this.name)
+ name: this.globalName
};
},
@@ -22,9 +22,13 @@ _.constructor("Monarch.Model.CompositeTuple", {
return this.leftTuple.record(table) || this.rightTuple.record(table);
},
- equals: function(other) {
+ isEqual: function(other) {
if (!other.constructor === this.constructor) return false;
- return this.leftTuple.equals(other.leftTuple) && this.rightTuple.equals(other.rightTuple);
+ return this.leftTuple.isEqual(other.leftTuple) && this.rightTuple.isEqual(other.rightTuple);
+ },
+
+ wireRepresentation: function() {
+ return [this.leftTuple.wireRepresentation(), this.rightTuple.wireRepresentation()]
}
});
Oops, something went wrong.

0 comments on commit b5f1fd5

Please sign in to comment.