Anonymous avatar Anonymous committed d0e9ff5

starting to hook in response processing infrastructure. For now register
a single catch all response processor that does nothing.

Comments (0)

Files changed (3)

src/obviel/obviel-session.js

 
         for (i = 0; i < objs.length; i++) {
             info = this.getClassifier(objs[i]);
-
             var group = mapping.get(info.key);
             if (group === undefined) {
                 group = new Group(info.classifier, info.key);
                 return {key: key, classifier: this.classifiers[i]};
             }
         }
-        throw new Error("Cannot classify action");
+        throw new Error("Cannot classify object");
     };
 
     var groupCompare = function(a, b) {

src/obviel/obviel-sync-2.js

 obviel.sync = {};
 
 (function($, module) {
+    var MINIMUM_PRIORITY = -1000000;
 
     module.Config = function(name) {
         this.name = name;
     };
     
     module.Receiver = function(name) {
-        this.name = name;
-        this.priority = 0;
+        module.Config.call(this, name);
     };
 
     module.Receiver.prototype = new module.Config();
     module.Receiver.prototype.constructor = module.Receiver;
 
+    module.CatchAllReceiver = function() {
+        module.Receiver.call(this, 'catchall');
+        this.priority = MINIMUM_PRIORITY;
+    };
+
+    module.CatchAllReceiver.prototype = new module.Receiver();
+    module.CatchAllReceiver.prototype.constructor = module.CatchAllReceiver;
+    
+    module.CatchAllReceiver.prototype.discriminator = function(obj) {
+        return {name: 'catchall'};
+    };
+    
+    module.CatchAllReceiver.prototype.process = function() {
+        // do nothing
+    };
+
     var Processor = function() {
         this.configs = {};
     };
             throw new Error("cannot extend config with name: " + config.name);
         }
         this.configs[config.name] = registeredConfig.clone(config);
-
     };
 
     Processor.prototype.getPrioritized = function() {
         if (!$.isArray(objs)) {
             objs = [objs];
         }
-        //return this.receiverProcessor.process(this, objs);
-        return;
+        return this.receiverProcessor.process(this, objs);
     };
 
     module.Connection.prototype.session = function() {
         this.sender(new module.HttpAddSender());
         this.sender(new module.HttpUpdateSender());
         this.sender(new module.HttpTouchSender());
+        this.receiver(new module.CatchAllReceiver());
     };
 
     module.HttpConnection.prototype = new module.Connection();

src/test/test-obviel-sync-2.js

 
         assert(done);
         assert(mockResponder.getDatas(), [obj, item]);
+    },
+
+    "http custom response processing": function() {
+        var url = "/path";
+        var mockResponder = new MockResponder();
+        this.server.respondWith('POST', url, function(request) {
+            request.respond(200, {'Content-Type': 'application/json'},
+                            JSON.stringify({id: 1, 'foo': 'BAZ'}));
+        });
+
+        var obj = {id: 1, foo: "Foo", updateUrl: url};
+
+        var conn = new obviel.sync.HttpConnection();
+        conn.sender({
+            name: 'update',
+            response: function(data) {
+                obj.foo = data.foo;
+            }
+        });
+        
+        var session = conn.session();
+        var m = session.mutator(obj);
+        m.set("foo", "FOO");
+        
+        session.commit();
+        this.server.respond();
+        assert.equals(obj.foo, 'BAZ');
     }
 
+        // var CustomReceiver = function() {
+        //     obviel.sync.Receiver.call(this, "custom");
+        // };
+
+        // CustomReceiver.prototype = new obviel.sync.Receiver();
+        // CustomReceiver.prototype.constructor = CustomReceiver;
+
+        // CustomReceiver.prototype.discriminator = function(obj) {
+        //     return true;
+        // };
+        // CustomReceiver.prototype.process = function() {
+            
+        // };
+
+
 });
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.