[ADD] explanation + interaction of journals + chart of accounts

After discussion with fp this probably isn't the direction (ish), but
want to checkpoint this in order to work on other stuff earlier in the
document, but not commit a single gigantic blob of stuff.
This commit is contained in:
Xavier Morel
2015-02-17 16:38:00 +01:00
parent 0ab12904e1
commit 931c1c8ec3
10 changed files with 5615 additions and 329 deletions
+48
View File
@@ -0,0 +1,48 @@
function createAtom(val, options) {
var watchers = {};
var validator = options && options.validator || function () { return true; };
function transition(next) {
if (!validator(next)) {
var err = new Error(next + " failed validation");
err.name = "AssertionError";
throw err;
}
var prev = val;
val = next;
Object.keys(watchers).forEach(function (k) {
watchers[k](k, atom, prev, next);
});
}
var atom = {
addWatch: function (key, fn) {
watchers[key] = fn;
},
removeWatch: function (key) {
delete watchers[key];
},
swap: function (fn) {
var args = [val].concat([].slice.call(arguments, 1));
transition(fn.apply(null, args));
},
reset: function (v) {
transition(v);
},
deref: function () {
return val;
},
toString: function () {
return "Atom(" + JSON.stringify(val) + ")";
}
};
return atom;
}