Created
September 23, 2013 21:00
-
-
Save sthalik/6676914 to your computer and use it in GitHub Desktop.
for Mike, unfinished, untested, 20130923
This file contains 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
var Sheet = (function () { | |
"use strict"; | |
var Integrity = []; // XXX TODO add integrity togglage -sh | |
var CellStack = []; | |
function BaseCell(formula) { | |
this._cached_value = null; | |
this._formula = formula; | |
this._fresh = false; | |
this._deps = []; | |
} | |
BaseCell.prototype.value = function () { | |
if (this._fresh) { | |
if (CellStack.length > 0) { | |
CellStack[CellStack.length - 1].deps.push(this); | |
} | |
return this._cached_value; | |
} | |
else { | |
var deps = {deps: []}; | |
CellStack.push(deps); | |
var ret = this._formula(); | |
CellStack.pop(); | |
// XXX do some circularity checks to avoid stack overflow -sh | |
this._cached_value = ret; | |
this._fresh = true; | |
this._deps = deps; | |
if (this._filter_value(ret)) { | |
this._pre_update(ret); | |
for (var x in deps) { | |
//noinspection JSUnfilteredForInLoop | |
x._invalidate(); | |
} | |
this._post_update(); | |
} | |
return ret; | |
} | |
}; | |
BaseCell.prototype._invalidate = function() { | |
self._fresh = false; | |
for (var x in self._deps) { | |
// NB all are derived from BaseCell -sh | |
//noinspection JSUnfilteredForInLoop | |
x._invalidate(); | |
} | |
}; | |
BaseCell.prototype._filter_value = function(datum) { | |
return datum; | |
}; | |
BaseCell.prototype._pre_update = function() { | |
// for events -sh | |
}; | |
BaseCell.prototype._post_update = function() { | |
// NB this is for events | |
// typical usage, invalidate deps, force them to recompute, | |
// revert back to null value -sh | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment