Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added delayed execute and changed constructor name

  • Loading branch information...
commit 5597c4e77aa9174d100ad48e55761b457ee11427 1 parent 3af50e8
Joe DePung authored
Showing with 40 additions and 36 deletions.
  1. +1 −1  index.js
  2. +39 −35 plan.js
View
2  index.js
@@ -32,7 +32,7 @@ function ohnoes(deferred, _, what_happened) {
}, 1000);
}
-var lol_plan = new PlanJS({
+var lol_plan = new PlanJs({
first: "HAI",
steps: {
"HAI": { action: hai, resolve: "GIMMEH", reject: "KTHXBY" },
View
74 plan.js
@@ -1,42 +1,46 @@
-// Plan.JS
+// plan.js
// Author: Benjamin P Lee
// License: Creative Commons Attribution 3.0 Unported License (see source README)
-var PlanJS = (function() {
- function PlanConstructor(details) {
- this.steps = details.steps;
- this.first = details.first;
- };
-
- PlanConstructor.prototype = {
- execute: function(context) {
- this.take_step(this.first, [context]);
- },
- take_step: function(step_name, args) {
- var step = this.steps[step_name];
-
- if(step) {
- var deferred = new $.Deferred()
+var PlanJs = (function () {
+ function PlanConstructor(details) {
+ this.steps = details.steps;
+ this.first = details.first;
+ };
+
+ PlanConstructor.prototype = {
+ execute: function (context) {
+ this.take_step(this.first, [context]);
+ },
+ take_step: function (step_name, args) {
+ var step = this.steps[step_name];
+
+ if (step) {
+ var deferred = new $.Deferred()
.done(this.take_future_step(step.resolve, args[0]))
.fail(this.take_future_step(step.reject, args[0]))
.always(this.take_future_step(step.always, args[0]));
- args.unshift(deferred);
-
- step.action.apply({}, args);
- }
- },
- take_future_step: function(step_name, context) {
- var that = this;
-
- return function() {
- var args = Array.prototype.slice.call(arguments);
- args.unshift(context);
-
- that.take_step(step_name, args);
- };
- }
- };
-
- return PlanConstructor;
-})();
+ args.unshift(deferred);
+
+ step.action.apply({}, args);
+ }
+ },
+ take_future_step: function (step_name, context) {
+ var that = this;
+
+ return function () {
+ var args = Array.prototype.slice.call(arguments);
+ args.unshift(context);
+
+ that.take_step(step_name, args);
+ };
+ },
+ execute_later: function (context) {
+ var that = this;
+ return function () { that.execute(context); };
+ }
+ };
+
+ return PlanConstructor;
+})();
Please sign in to comment.
Something went wrong with that request. Please try again.