Created
February 18, 2012 05:10
-
-
Save jmarnold/1857553 to your computer and use it in GitHub Desktop.
jquery.continuations samples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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); | |
}()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The Server module is just a helper for mocking the AJAX responses necessary to properly illustrate the usage.