Skip to content

Instantly share code, notes, and snippets.

@jmarnold
Created February 18, 2012 05:10
Show Gist options
  • Save jmarnold/1857553 to your computer and use it in GitHub Desktop.
Save jmarnold/1857553 to your computer and use it in GitHub Desktop.
jquery.continuations samples
(function() {
// Illustrates prototype extensions to the core continuation object
$.continuations.continuation.prototype.dialog = function () {
if (!this.success || typeof (this.form) === 'undefined') {
return $([]);
}
return this.form.parents('.ui-dialog-content');
};
// Illustrates a custom policy
var closeDialogPolicy = {
matches: function (continuation) {
return continuation.isCorrelated()
&& continuation.options.closeDialog
&& continuation.dialog().size() != 0;
},
execute: function (continuation) {
var element = continuation.dialog();
element.dialog('close');
}
};
// And here's how to wire it up
$.continuations.applyPolicy(closeDialogPolicy);
}());
Server = (function() {
var module = function() { };
var server = sinon.fakeServer.create();
var setResponse = function() {};
module.stubContinuation = function(continuation) {
setResponse = function(request) {
server.respondWith([200, {
'Content-Type': 'application/json',
'X-Correlation-Id': request.correlationId
}, JSON.stringify(continuation)
]);
};
};
module.onStart = function(request) {
module.reset();
setResponse(request);
};
module.respond = function() {
server.respond();
};
module.reset = function() {
server.restore();
server = sinon.fakeServer.create();
};
amplify.subscribe('AjaxStarted', module.onStart);
return module;
}());
@jmarnold
Copy link
Author

The Server module is just a helper for mocking the AJAX responses necessary to properly illustrate the usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment