X-Git-Url: https://git.distorted.org.uk/~mdw/dep-ui/blobdiff_plain/9c4e8d7f507407a9a5579842617f460b61584c56..6cfd4191b11af6db92fd970b7b6f9e2f9c876d83:/dep.js diff --git a/dep.js b/dep.js index 4376b89..9dd42b4 100644 --- a/dep.js +++ b/dep.js @@ -21,11 +21,11 @@ * along with this program; if not, see . */ -var DEP = { }; (function () { with (DEP) { +var DEP = { }; (function () { /*----- Utility functions and classes -------------------------------------*/ -DEP.dolist = function (list, func) { +function dolist(list, func) { /* Apply FUNC to each element of LIST, discarding the results. * * JavaScript's looping iterates over indices rather than values, which is @@ -36,6 +36,7 @@ DEP.dolist = function (list, func) { var i; for (i in list) func(list[i]); } +DEP.dolist = dolist; function eql(x, y) { /* A standard equality function, suitable for detecting changes to `Dep' @@ -50,18 +51,19 @@ function eql(x, y) { * that the set of Tags is basically determined by the static structure of * the program. */ -DEP.Tag = function (what) { +function Tag(what) { this.what = what; } Tag.prototype = { toString: function () { return '#{Tag ' + this.what + '}'; } } +DEP.Tag = Tag; /* A Generation is like a Tag, except that it's expected that a program will * manufacture Generations repeatedly, and perhaps use them to determine * whether an object is `up-to-date' in some sense. */ -DEP.Generation = function (what) { +function Generation(what) { this.what = what; this.seq = Generation._next++; } @@ -95,8 +97,11 @@ var PENDING = []; // Deps awaiting recomputation. /*----- Exceptions --------------------------------------------------------*/ -DEP.CircularDependency = new Tag('CircularDependency'); -DEP.BusyRecomputing = new Tag('BusyRecomputing'); +CircularDependency = new Tag('CircularDependency'); +DEP.CircularDependency = CircularDependency; + +BusyRecomputing = new Tag('BusyRecomputing'); +DEP.BusyRecomputing = BusyRecomputing; /*----- Main code ---------------------------------------------------------*/ @@ -112,7 +117,7 @@ DEP.BusyRecomputing = new Tag('BusyRecomputing'); * causes that `Dep' to become bad in turn. */ -DEP.Dep = function (value, maybefunc) { +function Dep(value, maybefunc) { /* Initialize a new `Dep' object. * * Handling of the arguments is a little fiddly. If two arguments are @@ -177,6 +182,7 @@ DEP.Dep = function (value, maybefunc) { } } +DEP.Dep = Dep; Dep._seq = 0; // Next sequence number to allocate. Dep.prototype = { @@ -416,7 +422,7 @@ Dep.prototype = { } }; -DEP.orelse = function (thunk, errthunk) { +function orelse(thunk, errthunk) { /* Call THUNK. If it succeeds, then return its result. If THUNK * reads a bad dep then call ERRTHINK and return its result instead. */ @@ -428,11 +434,13 @@ DEP.orelse = function (thunk, errthunk) { else throw e; } } +DEP.orelse = orelse; -DEP.bad = function () { +function bad() { /* For use in a value-function: make the dep be bad. */ throw BAD; } +DEP.bad = bad; function recompute_pending() { /* Recompute any pending dependencies. @@ -463,7 +471,7 @@ function recompute_pending() { } } -DEP.with_frozen = function (body, delay) { +function with_frozen(body, delay) { /* Call BODY with dependencies frozen. * * If the BODY function changes any dep values (using D.set_value(...)) @@ -507,6 +515,7 @@ DEP.with_frozen = function (body, delay) { break; } } +DEP.with_frozen = with_frozen; /*----- That's all, folks -------------------------------------------------*/ -} })(); +})();