diff --git a/ajax/libs/reactive-coffee/1.1.0/reactive-coffee.js b/ajax/libs/reactive-coffee/1.1.0/reactive-coffee.js new file mode 100644 index 000000000..11d22c518 --- /dev/null +++ b/ajax/libs/reactive-coffee/1.1.0/reactive-coffee.js @@ -0,0 +1,1748 @@ +(function() { + var rxFactory, + __slice = [].slice, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + rxFactory = function(_, _str, $) { + var DepArray, DepCell, DepMap, DepMgr, Ev, FakeObsCell, FakeSrcCell, IndexedArray, IndexedDepArray, IndexedMappedDepArray, MappedDepArray, ObsArray, ObsCell, ObsMap, ObsMapEntryCell, RawHtml, Recorder, SrcArray, SrcCell, SrcMap, SrcMapEntryCell, asyncBind, bind, depMgr, ev, events, firstWhere, flatten, lagBind, mkAtts, mkMap, mktag, mkuid, nextUid, nthWhere, permToSplices, popKey, postLagBind, prop, propSet, props, recorder, rx, rxt, setDynProp, setProp, specialAttrs, sum, tag, tags, _fn, _i, _len, _ref, _ref1, _ref2, _ref3, _ref4, + _this = this; + + rx = {}; + nextUid = 0; + mkuid = function() { + return nextUid += 1; + }; + popKey = function(x, k) { + var v; + + if (!(k in x)) { + throw new Error('object has no key ' + k); + } + v = x[k]; + delete x[k]; + return v; + }; + nthWhere = function(xs, n, f) { + var i, x, _i, _len; + + for (i = _i = 0, _len = xs.length; _i < _len; i = ++_i) { + x = xs[i]; + if (f(x) && (n -= 1) < 0) { + return [x, i]; + } + } + return [null, -1]; + }; + firstWhere = function(xs, f) { + return nthWhere(xs, 0, f); + }; + mkMap = function(xs) { + var k, map, v, _i, _len, _ref; + + if (xs == null) { + xs = []; + } + map = Object.create != null ? Object.create(null) : {}; + if (_.isArray(xs)) { + for (_i = 0, _len = xs.length; _i < _len; _i++) { + _ref = xs[_i], k = _ref[0], v = _ref[1]; + map[k] = v; + } + } else { + for (k in xs) { + v = xs[k]; + map[k] = v; + } + } + return map; + }; + sum = function(xs) { + var n, x, _i, _len; + + n = 0; + for (_i = 0, _len = xs.length; _i < _len; _i++) { + x = xs[_i]; + n += x; + } + return n; + }; + DepMgr = rx.DepMgr = (function() { + function DepMgr() { + this.uid2src = {}; + this.buffering = 0; + this.buffer = []; + } + + DepMgr.prototype.sub = function(uid, src) { + return this.uid2src[uid] = src; + }; + + DepMgr.prototype.unsub = function(uid) { + return popKey(this.uid2src, uid); + }; + + DepMgr.prototype.transaction = function(f) { + var b, res, _i, _len, _ref; + + this.buffering += 1; + try { + res = f(); + } finally { + this.buffering -= 1; + if (this.buffering === 0) { + _ref = this.buffer; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + b = _ref[_i]; + b(); + } + this.buffer = []; + } + } + return res; + }; + + return DepMgr; + + })(); + rx._depMgr = depMgr = new DepMgr(); + Ev = rx.Ev = (function() { + function Ev(inits) { + this.inits = inits; + this.subs = mkMap(); + } + + Ev.prototype.sub = function(listener) { + var init, uid, _i, _len, _ref; + + uid = mkuid(); + if (this.inits != null) { + _ref = this.inits(); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + init = _ref[_i]; + listener(init); + } + } + this.subs[uid] = listener; + depMgr.sub(uid, this); + return uid; + }; + + Ev.prototype.pub = function(data) { + var listener, uid, _ref, _results, + _this = this; + + if (depMgr.buffering) { + return depMgr.buffer.push(function() { + return _this.pub(data); + }); + } else { + _ref = this.subs; + _results = []; + for (uid in _ref) { + listener = _ref[uid]; + _results.push(listener(data)); + } + return _results; + } + }; + + Ev.prototype.unsub = function(uid) { + popKey(this.subs, uid); + return depMgr.unsub(uid, this); + }; + + Ev.prototype.scoped = function(listener, context) { + var uid; + + uid = this.sub(listener); + try { + return context(); + } finally { + this.unsub(uid); + } + }; + + return Ev; + + })(); + rx.skipFirst = function(f) { + var first; + + first = true; + return function() { + var args; + + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (first) { + return first = false; + } else { + return f.apply(null, args); + } + }; + }; + Recorder = rx.Recorder = (function() { + function Recorder() { + this.stack = []; + this.isMutating = false; + this.isIgnoring = false; + this.onMutationWarning = new Ev(); + } + + Recorder.prototype.record = function(dep, f) { + var wasIgnoring, wasMutating; + + if (this.stack.length > 0 && !this.isMutating) { + _(this.stack).last().addNestedBind(dep); + } + this.stack.push(dep); + wasMutating = this.isMutating; + this.isMutating = false; + wasIgnoring = this.isIgnoring; + this.isIgnoring = false; + try { + return f(); + } finally { + this.isIgnoring = wasIgnoring; + this.isMutating = wasMutating; + this.stack.pop(); + } + }; + + Recorder.prototype.sub = function(sub) { + var handle, topCell; + + if (this.stack.length > 0 && !this.isIgnoring) { + topCell = _(this.stack).last(); + return handle = sub(topCell); + } + }; + + Recorder.prototype.addCleanup = function(cleanup) { + if (this.stack.length > 0) { + return _(this.stack).last().addCleanup(cleanup); + } + }; + + Recorder.prototype.mutating = function(f) { + var wasMutating; + + if (this.stack.length > 0) { + console.warn('Mutation to observable detected during a bind context'); + this.onMutationWarning.pub(null); + } + wasMutating = this.isMutating; + this.isMutating = true; + try { + return f(); + } finally { + this.isMutating = wasMutating; + } + }; + + Recorder.prototype.ignoring = function(f) { + var wasIgnoring; + + wasIgnoring = this.isIgnoring; + this.isIgnoring = true; + try { + return f(); + } finally { + this.isIgnoring = wasIgnoring; + } + }; + + return Recorder; + + })(); + rx._recorder = recorder = new Recorder(); + rx.asyncBind = asyncBind = function(init, f) { + var dep; + + dep = new DepCell(f, init); + dep.refresh(); + return dep; + }; + rx.bind = bind = function(f) { + return asyncBind(null, function() { + return this.done(this.record(f)); + }); + }; + rx.lagBind = lagBind = function(lag, init, f) { + var timeout; + + timeout = null; + return asyncBind(init, function() { + var _this = this; + + if (timeout != null) { + clearTimeout(timeout); + } + return timeout = setTimeout(function() { + return _this.done(_this.record(f)); + }, lag); + }); + }; + rx.postLagBind = postLagBind = function(init, f) { + var timeout; + + timeout = null; + return asyncBind(init, function() { + var ms, val, _ref, + _this = this; + + _ref = this.record(f), val = _ref.val, ms = _ref.ms; + if (timeout != null) { + clearTimeout(timeout); + } + return timeout = setTimeout((function() { + return _this.done(val); + }), ms); + }); + }; + rx.snap = function(f) { + return recorder.ignoring(f); + }; + rx.onDispose = function(cleanup) { + return recorder.addCleanup(cleanup); + }; + rx.autoSub = function(ev, listener) { + var subid; + + subid = ev.sub(listener); + rx.onDispose(function() { + return ev.unsub(subid); + }); + return subid; + }; + ObsCell = rx.ObsCell = (function() { + function ObsCell(x) { + var _ref, + _this = this; + + this.x = x; + this.x = (_ref = this.x) != null ? _ref : null; + this.onSet = new Ev(function() { + return [[null, _this.x]]; + }); + } + + ObsCell.prototype.get = function() { + var _this = this; + + recorder.sub(function(target) { + return rx.autoSub(_this.onSet, function() { + return target.refresh(); + }); + }); + return this.x; + }; + + return ObsCell; + + })(); + SrcCell = rx.SrcCell = (function(_super) { + __extends(SrcCell, _super); + + function SrcCell() { + _ref = SrcCell.__super__.constructor.apply(this, arguments); + return _ref; + } + + SrcCell.prototype.set = function(x) { + var _this = this; + + return recorder.mutating(function() { + var old; + + if (_this.x !== x) { + old = _this.x; + _this.x = x; + _this.onSet.pub([old, x]); + return old; + } + }); + }; + + return SrcCell; + + })(ObsCell); + DepCell = rx.DepCell = (function(_super) { + __extends(DepCell, _super); + + function DepCell(body, init) { + this.body = body; + DepCell.__super__.constructor.call(this, init != null ? init : null); + this.refreshing = false; + this.nestedBinds = []; + this.cleanups = []; + } + + DepCell.prototype.refresh = function() { + var env, isSynchronous, old, realDone, syncResult, + _this = this; + + if (!this.refreshing) { + old = this.x; + realDone = function(x) { + _this.x = x; + return _this.onSet.pub([old, _this.x]); + }; + ({ + recorded: false + }); + syncResult = null; + isSynchronous = false; + env = { + record: function(f) { + var recorded, res; + + if (!_this.refreshing) { + _this.disconnect(); + if (recorded) { + throw new Error('this refresh has already recorded its dependencies'); + } + _this.refreshing = true; + recorded = true; + try { + res = recorder.record(_this, function() { + return f.call(env); + }); + } finally { + _this.refreshing = false; + } + if (isSynchronous) { + realDone(syncResult); + } + return res; + } + }, + done: function(x) { + if (old !== x) { + if (_this.refreshing) { + isSynchronous = true; + return syncResult = x; + } else { + return realDone(x); + } + } + } + }; + return this.body.call(env); + } + }; + + DepCell.prototype.disconnect = function() { + var cleanup, nestedBind, _i, _j, _len, _len1, _ref1, _ref2; + + _ref1 = this.cleanups; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + cleanup = _ref1[_i]; + cleanup(); + } + _ref2 = this.nestedBinds; + for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { + nestedBind = _ref2[_j]; + nestedBind.disconnect(); + } + this.nestedBinds = []; + return this.cleanups = []; + }; + + DepCell.prototype.addNestedBind = function(nestedBind) { + return this.nestedBinds.push(nestedBind); + }; + + DepCell.prototype.addCleanup = function(cleanup) { + return this.cleanups.push(cleanup); + }; + + return DepCell; + + })(ObsCell); + ObsArray = rx.ObsArray = (function() { + function ObsArray(xs, diff) { + var _this = this; + + this.xs = xs != null ? xs : []; + this.diff = diff != null ? diff : rx.basicDiff(); + this.onChange = new Ev(function() { + return [[0, [], _this.xs]]; + }); + this.indexed_ = null; + } + + ObsArray.prototype.all = function() { + var _this = this; + + recorder.sub(function(target) { + return rx.autoSub(_this.onChange, function() { + return target.refresh(); + }); + }); + return _.clone(this.xs); + }; + + ObsArray.prototype.raw = function() { + var _this = this; + + recorder.sub(function(target) { + return rx.autoSub(_this.onChange, function() { + return target.refresh(); + }); + }); + return this.xs; + }; + + ObsArray.prototype.at = function(i) { + var _this = this; + + recorder.sub(function(target) { + return rx.autoSub(_this.onChange, function(_arg) { + var added, index, removed; + + index = _arg[0], removed = _arg[1], added = _arg[2]; + if (index === i) { + return target.refresh(); + } + }); + }); + return this.xs[i]; + }; + + ObsArray.prototype.length = function() { + var _this = this; + + recorder.sub(function(target) { + return rx.autoSub(_this.onChange, function(_arg) { + var added, index, removed; + + index = _arg[0], removed = _arg[1], added = _arg[2]; + if (removed.length !== added.length) { + return target.refresh(); + } + }); + }); + return this.xs.length; + }; + + ObsArray.prototype.map = function(f) { + var ys; + + ys = new MappedDepArray(); + rx.autoSub(this.onChange, function(_arg) { + var added, index, removed; + + index = _arg[0], removed = _arg[1], added = _arg[2]; + return ys.realSplice(index, removed.length, added.map(f)); + }); + return ys; + }; + + ObsArray.prototype.indexed = function() { + var _this = this; + + if (this.indexed_ == null) { + this.indexed_ = new IndexedDepArray(); + rx.autoSub(this.onChange, function(_arg) { + var added, index, removed; + + index = _arg[0], removed = _arg[1], added = _arg[2]; + return _this.indexed_.realSplice(index, removed.length, added); + }); + } + return this.indexed_; + }; + + ObsArray.prototype.concat = function(that) { + return rx.concat(this, that); + }; + + ObsArray.prototype.realSplice = function(index, count, additions) { + var removed; + + removed = this.xs.splice.apply(this.xs, [index, count].concat(additions)); + return this.onChange.pub([index, removed, additions]); + }; + + ObsArray.prototype._update = function(val, diff) { + var additions, count, fullSplice, index, old, splice, splices, x, _i, _len, _ref1, _results; + + if (diff == null) { + diff = this.diff; + } + old = this.xs; + fullSplice = [0, old.length, val]; + x = null; + splices = diff != null ? (_ref1 = permToSplices(old.length, val, diff(old, val))) != null ? _ref1 : [fullSplice] : [fullSplice]; + _results = []; + for (_i = 0, _len = splices.length; _i < _len; _i++) { + splice = splices[_i]; + index = splice[0], count = splice[1], additions = splice[2]; + _results.push(this.realSplice(index, count, additions)); + } + return _results; + }; + + return ObsArray; + + })(); + SrcArray = rx.SrcArray = (function(_super) { + __extends(SrcArray, _super); + + function SrcArray() { + _ref1 = SrcArray.__super__.constructor.apply(this, arguments); + return _ref1; + } + + SrcArray.prototype.spliceArray = function(index, count, additions) { + var _this = this; + + return recorder.mutating(function() { + return _this.realSplice(index, count, additions); + }); + }; + + SrcArray.prototype.splice = function() { + var additions, count, index; + + index = arguments[0], count = arguments[1], additions = 3 <= arguments.length ? __slice.call(arguments, 2) : []; + return this.spliceArray(index, count, additions); + }; + + SrcArray.prototype.insert = function(x, index) { + return this.splice(index, 0, x); + }; + + SrcArray.prototype.remove = function(x) { + var i; + + i = _(this.raw()).indexOf(x); + if (i >= 0) { + return this.removeAt(i); + } + }; + + SrcArray.prototype.removeAt = function(index) { + return this.splice(index, 1); + }; + + SrcArray.prototype.push = function(x) { + return this.splice(this.length(), 0, x); + }; + + SrcArray.prototype.put = function(i, x) { + return this.splice(i, 1, x); + }; + + SrcArray.prototype.replace = function(xs) { + return this.spliceArray(0, this.length(), xs); + }; + + SrcArray.prototype.update = function(xs) { + var _this = this; + + return recorder.mutating(function() { + return _this._update(xs); + }); + }; + + return SrcArray; + + })(ObsArray); + MappedDepArray = rx.MappedDepArray = (function(_super) { + __extends(MappedDepArray, _super); + + function MappedDepArray() { + _ref2 = MappedDepArray.__super__.constructor.apply(this, arguments); + return _ref2; + } + + return MappedDepArray; + + })(ObsArray); + IndexedDepArray = rx.IndexedDepArray = (function(_super) { + __extends(IndexedDepArray, _super); + + function IndexedDepArray(xs, diff) { + var i, x, + _this = this; + + if (xs == null) { + xs = []; + } + IndexedDepArray.__super__.constructor.call(this, xs, diff); + this.is = (function() { + var _i, _len, _ref3, _results; + + _ref3 = this.xs; + _results = []; + for (i = _i = 0, _len = _ref3.length; _i < _len; i = ++_i) { + x = _ref3[i]; + _results.push(rx.cell(i)); + } + return _results; + }).call(this); + this.onChange = new Ev(function() { + return [[0, [], _.zip(_this.xs, _this.is)]]; + }); + } + + IndexedDepArray.prototype.map = function(f) { + var ys; + + ys = new IndexedMappedDepArray(); + rx.autoSub(this.onChange, function(_arg) { + var a, added, i, index, removed; + + index = _arg[0], removed = _arg[1], added = _arg[2]; + return ys.realSplice(index, removed.length, (function() { + var _i, _len, _ref3, _results; + + _results = []; + for (_i = 0, _len = added.length; _i < _len; _i++) { + _ref3 = added[_i], a = _ref3[0], i = _ref3[1]; + _results.push(f(a, i)); + } + return _results; + })()); + }); + return ys; + }; + + IndexedDepArray.prototype.realSplice = function(index, count, additions) { + var i, newIs, offset, removed, _i, _len, _ref3, _ref4, _ref5; + + removed = (_ref3 = this.xs).splice.apply(_ref3, [index, count].concat(__slice.call(additions))); + _ref4 = this.is.slice(index + count); + for (offset = _i = 0, _len = _ref4.length; _i < _len; offset = ++_i) { + i = _ref4[offset]; + i.set(index + additions.length + offset); + } + newIs = (function() { + var _j, _ref5, _results; + + _results = []; + for (i = _j = 0, _ref5 = additions.length; 0 <= _ref5 ? _j < _ref5 : _j > _ref5; i = 0 <= _ref5 ? ++_j : --_j) { + _results.push(rx.cell(index + i)); + } + return _results; + })(); + (_ref5 = this.is).splice.apply(_ref5, [index, count].concat(__slice.call(newIs))); + return this.onChange.pub([index, removed, _.zip(additions, newIs)]); + }; + + return IndexedDepArray; + + })(ObsArray); + IndexedMappedDepArray = rx.IndexedMappedDepArray = (function(_super) { + __extends(IndexedMappedDepArray, _super); + + function IndexedMappedDepArray() { + _ref3 = IndexedMappedDepArray.__super__.constructor.apply(this, arguments); + return _ref3; + } + + return IndexedMappedDepArray; + + })(IndexedDepArray); + DepArray = rx.DepArray = (function(_super) { + __extends(DepArray, _super); + + function DepArray(f, diff) { + var _this = this; + + this.f = f; + DepArray.__super__.constructor.call(this, [], diff); + rx.autoSub((bind(function() { + return _this.f(); + })).onSet, function(_arg) { + var old, val; + + old = _arg[0], val = _arg[1]; + return _this._update(val); + }); + } + + return DepArray; + + })(ObsArray); + IndexedArray = rx.IndexedArray = (function(_super) { + __extends(IndexedArray, _super); + + function IndexedArray(xs) { + this.xs = xs; + } + + IndexedArray.prototype.map = function(f) { + var ys; + + ys = new MappedDepArray(); + rx.autoSub(this.xs.onChange, function(_arg) { + var added, index, removed; + + index = _arg[0], removed = _arg[1], added = _arg[2]; + return ys.realSplice(index, removed.length, added.map(f)); + }); + return ys; + }; + + return IndexedArray; + + })(DepArray); + rx.concat = function() { + var repLens, xs, xss, ys; + + xss = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + ys = new MappedDepArray(); + repLens = (function() { + var _i, _len, _results; + + _results = []; + for (_i = 0, _len = xss.length; _i < _len; _i++) { + xs = xss[_i]; + _results.push(0); + } + return _results; + })(); + xss.map(function(xs, i) { + return rx.autoSub(xs.onChange, function(_arg) { + var added, index, removed, xsOffset; + + index = _arg[0], removed = _arg[1], added = _arg[2]; + xsOffset = sum(repLens.slice(0, i)); + repLens[i] += added.length - removed.length; + return ys.realSplice(xsOffset + index, removed.length, added); + }); + }); + return ys; + }; + FakeSrcCell = rx.FakeSrcCell = (function(_super) { + __extends(FakeSrcCell, _super); + + function FakeSrcCell(_getter, _setter) { + this._getter = _getter; + this._setter = _setter; + } + + FakeSrcCell.prototype.get = function() { + return this._getter(); + }; + + FakeSrcCell.prototype.set = function(x) { + return this._setter(x); + }; + + return FakeSrcCell; + + })(SrcCell); + FakeObsCell = rx.FakeObsCell = (function(_super) { + __extends(FakeObsCell, _super); + + function FakeObsCell(_getter) { + this._getter = _getter; + } + + FakeObsCell.prototype.get = function() { + return this._getter(); + }; + + return FakeObsCell; + + })(ObsCell); + SrcMapEntryCell = rx.MapEntryCell = (function(_super) { + __extends(MapEntryCell, _super); + + function MapEntryCell(_map, _key) { + this._map = _map; + this._key = _key; + } + + MapEntryCell.prototype.get = function() { + return this._map.get(this._key); + }; + + MapEntryCell.prototype.set = function(x) { + return this._map.put(this._key, x); + }; + + return MapEntryCell; + + })(FakeSrcCell); + ObsMapEntryCell = rx.ObsMapEntryCell = (function(_super) { + __extends(ObsMapEntryCell, _super); + + function ObsMapEntryCell(_map, _key) { + this._map = _map; + this._key = _key; + } + + ObsMapEntryCell.prototype.get = function() { + return this._map.get(this._key); + }; + + return ObsMapEntryCell; + + })(FakeObsCell); + ObsMap = rx.ObsMap = (function() { + function ObsMap(x) { + var _this = this; + + this.x = x != null ? x : {}; + this.onAdd = new Ev(function() { + var k, v, _results; + + _results = []; + for (k in x) { + v = x[k]; + _results.push([k, v]); + } + return _results; + }); + this.onRemove = new Ev(); + this.onChange = new Ev(); + } + + ObsMap.prototype.get = function(key) { + var _this = this; + + recorder.sub(function(target) { + return rx.autoSub(_this.onAdd, function(_arg) { + var subkey, val; + + subkey = _arg[0], val = _arg[1]; + if (key === subkey) { + return target.refresh(); + } + }); + }); + recorder.sub(function(target) { + return rx.autoSub(_this.onChange, function(_arg) { + var old, subkey, val; + + subkey = _arg[0], old = _arg[1], val = _arg[2]; + if (key === subkey) { + return target.refresh(); + } + }); + }); + recorder.sub(function(target) { + return rx.autoSub(_this.onRemove, function(_arg) { + var old, subkey; + + subkey = _arg[0], old = _arg[1]; + if (key === subkey) { + return target.refresh(); + } + }); + }); + return this.x[key]; + }; + + ObsMap.prototype.all = function() { + var _this = this; + + recorder.sub(function(target) { + return rx.autoSub(_this.onAdd, function() { + return target.refresh(); + }); + }); + recorder.sub(function(target) { + return rx.autoSub(_this.onChange, function() { + return target.refresh(); + }); + }); + recorder.sub(function(target) { + return rx.autoSub(_this.onRemove, function() { + return target.refresh(); + }); + }); + return _.clone(this.x); + }; + + ObsMap.prototype.realPut = function(key, val) { + var old; + + if (key in this.x) { + old = this.x[key]; + this.x[key] = val; + this.onChange.pub([key, old, val]); + return old; + } else { + this.x[key] = val; + this.onAdd.pub([key, val]); + return void 0; + } + }; + + ObsMap.prototype.realRemove = function(key) { + var val; + + val = popKey(this.x, key); + this.onRemove.pub([key, val]); + return val; + }; + + ObsMap.prototype.cell = function(key) { + return new ObsMapEntryCell(this, key); + }; + + return ObsMap; + + })(); + SrcMap = rx.SrcMap = (function(_super) { + __extends(SrcMap, _super); + + function SrcMap() { + _ref4 = SrcMap.__super__.constructor.apply(this, arguments); + return _ref4; + } + + SrcMap.prototype.put = function(key, val) { + var _this = this; + + return recorder.mutating(function() { + return _this.realPut(key, val); + }); + }; + + SrcMap.prototype.remove = function(key) { + var _this = this; + + return recorder.mutating(function() { + return _this.realRemove(key); + }); + }; + + SrcMap.prototype.cell = function(key) { + return new SrcMapEntryCell(this, key); + }; + + return SrcMap; + + })(ObsMap); + DepMap = rx.DepMap = (function(_super) { + __extends(DepMap, _super); + + function DepMap(f) { + this.f = f; + DepMap.__super__.constructor.call(this); + rx.autoSub(new DepCell(this.f).onSet, function(_arg) { + var k, old, v, val, _results; + + old = _arg[0], val = _arg[1]; + for (k in old) { + v = old[k]; + if (!(k in val)) { + this.realRemove(k); + } + } + _results = []; + for (k in val) { + v = val[k]; + if (this.x[k] !== v) { + _results.push(this.realPut(k, v)); + } else { + _results.push(void 0); + } + } + return _results; + }); + } + + return DepMap; + + })(ObsMap); + rx.liftSpec = function(obj) { + var name, type, val; + + return _.object((function() { + var _i, _len, _ref5, _results; + + _ref5 = Object.getOwnPropertyNames(obj); + _results = []; + for (_i = 0, _len = _ref5.length; _i < _len; _i++) { + name = _ref5[_i]; + val = obj[name]; + if ((val != null) && (val instanceof rx.ObsMap || val instanceof rx.ObsCell || val instanceof rx.ObsArray)) { + continue; + } + type = _.isFunction(val) ? null : _.isArray(val) ? 'array' : 'cell'; + _results.push([ + name, { + type: type, + val: val + } + ]); + } + return _results; + })()); + }; + rx.lift = function(x, fieldspec) { + var name, spec; + + if (fieldspec == null) { + fieldspec = rx.liftSpec(x); + } + for (name in fieldspec) { + spec = fieldspec[name]; + x[name] = (function() { + switch (spec.type) { + case 'cell': + return rx.cell(x[name]); + case 'array': + return rx.array(x[name]); + case 'map': + return rx.map(x[name]); + default: + return x[name]; + } + })(); + } + return x; + }; + rx.unlift = function(x) { + var k, v; + + return _.object((function() { + var _results; + + _results = []; + for (k in x) { + v = x[k]; + _results.push([k, v instanceof rx.ObsCell ? v.get() : v instanceof rx.ObsArray ? v.all() : v]); + } + return _results; + })()); + }; + rx.reactify = function(obj, fieldspec) { + var arr, methName, name, spec; + + if (_.isArray(obj)) { + arr = rx.array(_.clone(obj)); + Object.defineProperties(obj, _.object((function() { + var _i, _len, _ref5, _results; + + _ref5 = _.functions(arr); + _results = []; + for (_i = 0, _len = _ref5.length; _i < _len; _i++) { + methName = _ref5[_i]; + if (methName !== 'length') { + _results.push((function(methName) { + var meth, newMeth, spec; + + meth = obj[methName]; + newMeth = function() { + var args, res, _ref6; + + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (meth != null) { + res = meth.call.apply(meth, [obj].concat(__slice.call(args))); + } + (_ref6 = arr[methName]).call.apply(_ref6, [arr].concat(__slice.call(args))); + return res; + }; + spec = { + configurable: true, + enumerable: false, + value: newMeth, + writable: true + }; + return [methName, spec]; + })(methName)); + } + } + return _results; + })())); + return obj; + } else { + return Object.defineProperties(obj, _.object((function() { + var _results; + + _results = []; + for (name in fieldspec) { + spec = fieldspec[name]; + _results.push((function(name, spec) { + var desc, obs, view, _ref5, _ref6; + + desc = null; + switch (spec.type) { + case 'cell': + obs = rx.cell((_ref5 = spec.val) != null ? _ref5 : null); + desc = { + configurable: true, + enumerable: true, + get: function() { + return obs.get(); + }, + set: function(x) { + return obs.set(x); + } + }; + break; + case 'array': + view = rx.reactify((_ref6 = spec.val) != null ? _ref6 : []); + desc = { + configurable: true, + enumerable: true, + get: function() { + view.raw(); + return view; + }, + set: function(x) { + view.splice.apply(view, [0, view.length].concat(__slice.call(x))); + return view; + } + }; + break; + default: + throw new Error("Unknown observable type: " + type); + } + return [name, desc]; + })(name, spec)); + } + return _results; + })())); + } + }; + rx.autoReactify = function(obj) { + var name, type, val; + + return rx.reactify(obj, _.object((function() { + var _i, _len, _ref5, _results; + + _ref5 = Object.getOwnPropertyNames(obj); + _results = []; + for (_i = 0, _len = _ref5.length; _i < _len; _i++) { + name = _ref5[_i]; + val = obj[name]; + if (val instanceof ObsMap || val instanceof ObsCell || val instanceof ObsArray) { + continue; + } + type = _.isFunction(val) ? null : _.isArray(val) ? 'array' : 'cell'; + _results.push([ + name, { + type: type, + val: val + } + ]); + } + return _results; + })())); + }; + _.extend(rx, { + cell: function(x) { + return new SrcCell(x); + }, + array: function(xs, diff) { + return new SrcArray(xs, diff); + }, + map: function(x) { + return new SrcMap(x); + } + }); + rx.flatten = function(xs) { + return new DepArray(function() { + var x; + + return _((function() { + var _i, _len, _results; + + _results = []; + for (_i = 0, _len = xs.length; _i < _len; _i++) { + x = xs[_i]; + if (x instanceof ObsArray) { + _results.push(x.raw()); + } else if (x instanceof ObsCell) { + _results.push(x.get()); + } else { + _results.push(x); + } + } + return _results; + })()).chain().flatten(true).filter(function(x) { + return x != null; + }).value(); + }); + }; + flatten = function(xss) { + var xs; + + xs = _.flatten(xss); + return rx.cellToArray(bind(function() { + return _.flatten(xss); + })); + }; + rx.cellToArray = function(cell, diff) { + return new DepArray((function() { + return cell.get(); + }), diff); + }; + rx.basicDiff = function(key) { + if (key == null) { + key = rx.smartUidify; + } + return function(oldXs, newXs) { + var i, oldKeys, x, _i, _len, _ref5, _results; + + oldKeys = mkMap((function() { + var _i, _len, _results; + + _results = []; + for (i = _i = 0, _len = oldXs.length; _i < _len; i = ++_i) { + x = oldXs[i]; + _results.push([key(x), i]); + } + return _results; + })()); + _results = []; + for (_i = 0, _len = newXs.length; _i < _len; _i++) { + x = newXs[_i]; + _results.push((_ref5 = oldKeys[key(x)]) != null ? _ref5 : -1); + } + return _results; + }; + }; + rx.uidify = function(x) { + var _ref5; + + return (_ref5 = x.__rxUid) != null ? _ref5 : (Object.defineProperty(x, '__rxUid', { + enumerable: false, + value: mkuid() + })).__rxUid; + }; + rx.smartUidify = function(x) { + if (_.isObject(x)) { + return rx.uidify(x); + } else { + return JSON.stringify(x); + } + }; + permToSplices = function(oldLength, newXs, perm) { + var cur, i, last, refs, splice, splices; + + refs = (function() { + var _i, _len, _results; + + _results = []; + for (_i = 0, _len = perm.length; _i < _len; _i++) { + i = perm[_i]; + if (i >= 0) { + _results.push(i); + } + } + return _results; + })(); + if (_.some((function() { + var _i, _ref5, _results; + + _results = []; + for (i = _i = 0, _ref5 = refs.length - 1; 0 <= _ref5 ? _i < _ref5 : _i > _ref5; i = 0 <= _ref5 ? ++_i : --_i) { + _results.push(refs[i + 1] - refs[i] <= 0); + } + return _results; + })())) { + return null; + } + splices = []; + last = -1; + i = 0; + while (i < perm.length) { + while (i < perm.length && perm[i] === last + 1) { + last += 1; + i += 1; + } + splice = { + index: i, + count: 0, + additions: [] + }; + while (i < perm.length && perm[i] === -1) { + splice.additions.push(newXs[i]); + i += 1; + } + cur = i === perm.length ? oldLength : perm[i]; + splice.count = cur - (last + 1); + if (splice.count > 0 || splice.additions.length > 0) { + splices.push([splice.index, splice.count, splice.additions]); + } + last = cur; + i += 1; + } + return splices; + }; + rx.transaction = function(f) { + return depMgr.transaction(f); + }; + if ($ != null) { + $.fn.rx = function(prop) { + var checked, focused, map, val; + + map = this.data('rx-map'); + if (map == null) { + this.data('rx-map', map = mkMap()); + } + if (prop in map) { + return map[prop]; + } + return map[prop] = (function() { + var _this = this; + + switch (prop) { + case 'focused': + focused = rx.cell(this.is(':focus')); + this.focus(function() { + return focused.set(true); + }); + this.blur(function() { + return focused.set(false); + }); + return focused; + case 'val': + val = rx.cell(this.val()); + this.change(function() { + return val.set(_this.val()); + }); + this.on('input', function() { + return val.set(_this.val()); + }); + return val; + case 'checked': + checked = rx.cell(this.is(':checked')); + this.change(function() { + return checked.set(_this.is(':checked')); + }); + return checked; + default: + throw new Error('Unknown reactive property type'); + } + }).call(this); + }; + rxt = {}; + RawHtml = rxt.RawHtml = (function() { + function RawHtml(html) { + this.html = html; + } + + return RawHtml; + + })(); + events = ["blur", "change", "click", "dblclick", "error", "focus", "focusin", "focusout", "hover", "keydown", "keypress", "keyup", "load", "mousedown", "mouseenter", "mouseleave", "mousemove", "mouseout", "mouseover", "mouseup", "ready", "resize", "scroll", "select", "submit", "toggle", "unload"]; + specialAttrs = rxt.specialAttrs = { + init: function(elt, fn) { + return fn.call(elt); + } + }; + _fn = function(ev) { + return specialAttrs[ev] = function(elt, fn) { + return elt[ev](function(e) { + return fn.call(elt, e); + }); + }; + }; + for (_i = 0, _len = events.length; _i < _len; _i++) { + ev = events[_i]; + _fn(ev); + } + props = ['async', 'autofocus', 'checked', 'location', 'multiple', 'readOnly', 'selected', 'selectedIndex', 'tagName', 'nodeName', 'nodeType', 'ownerDocument', 'defaultChecked', 'defaultSelected']; + propSet = _.object((function() { + var _j, _len1, _results; + + _results = []; + for (_j = 0, _len1 = props.length; _j < _len1; _j++) { + prop = props[_j]; + _results.push([prop, null]); + } + return _results; + })()); + setProp = function(elt, prop, val) { + if (prop === 'value') { + return elt.val(val); + } else if (prop in propSet) { + return elt.prop(prop, val); + } else { + return elt.attr(prop, val); + } + }; + setDynProp = function(elt, prop, val, xform) { + if (xform == null) { + xform = _.identity; + } + if (val instanceof ObsCell) { + return rx.autoSub(val.onSet, function(_arg) { + var n, o; + + o = _arg[0], n = _arg[1]; + return setProp(elt, prop, xform(n)); + }); + } else { + return setProp(elt, prop, xform(val)); + } + }; + rxt.mkAtts = mkAtts = function(attstr) { + return (function(atts) { + var cls, match; + + match = attstr.match(/[#](\w+)/); + if (match) { + atts.id = match[1]; + } + atts["class"] = ((function() { + var _j, _len1, _ref5, _results; + + _ref5 = attstr.match(/\.\w+/g); + _results = []; + for (_j = 0, _len1 = _ref5.length; _j < _len1; _j++) { + cls = _ref5[_j]; + _results.push(cls.replace(/^\./, '')); + } + return _results; + })()).join(' '); + return atts; + })({}); + }; + rxt.mktag = mktag = function(tag) { + return function(arg1, arg2) { + var attrs, contents, elt, key, name, toNodes, updateContents, value, _ref5, _ref6; + + _ref5 = (arg1 == null) && (arg2 == null) ? [{}, null] : arg1 instanceof Object && (arg2 != null) ? [arg1, arg2] : _.isString(arg1) && (arg2 != null) ? [mkAtts(arg1), arg2] : (arg2 == null) && _.isString(arg1) || arg1 instanceof Element || arg1 instanceof RawHtml || arg1 instanceof $ || _.isArray(arg1) || arg1 instanceof ObsCell || arg1 instanceof ObsArray ? [{}, arg1] : [arg1, null], attrs = _ref5[0], contents = _ref5[1]; + elt = $("<" + tag + "/>"); + _ref6 = _.omit(attrs, _.keys(specialAttrs)); + for (name in _ref6) { + value = _ref6[name]; + setDynProp(elt, name, value); + } + if (contents != null) { + toNodes = function(contents) { + var child, parsed, _j, _len1, _results; + + _results = []; + for (_j = 0, _len1 = contents.length; _j < _len1; _j++) { + child = contents[_j]; + if (_.isString(child)) { + _results.push(document.createTextNode(child)); + } else if (child instanceof Element) { + _results.push(child); + } else if (child instanceof RawHtml) { + parsed = $(child.html); + if (parsed.length !== 1) { + throw new Error('RawHtml must wrap a single element'); + } + _results.push(parsed[0]); + } else if (child instanceof $) { + if (child.length !== 1) { + throw new Error('jQuery object must wrap a single element'); + } + _results.push(child[0]); + } else { + throw new Error("Unknown element type in array: " + child.constructor.name + " (must be string, Element, RawHtml, or jQuery objects)"); + } + } + return _results; + }; + updateContents = function(contents) { + var covers, hasWidth, left, node, nodes, top; + + elt.html(''); + if (_.isArray(contents)) { + nodes = toNodes(contents); + elt.append(nodes); + if (false) { + hasWidth = function(node) { + var e; + + try { + return ($(node).width() != null) !== 0; + } catch (_error) { + e = _error; + return false; + } + }; + covers = (function() { + var _j, _len1, _ref7, _ref8, _results; + + _ref7 = nodes != null ? nodes : []; + _results = []; + for (_j = 0, _len1 = _ref7.length; _j < _len1; _j++) { + node = _ref7[_j]; + if (!(hasWidth(node))) { + continue; + } + _ref8 = $(node).offset(), left = _ref8.left, top = _ref8.top; + _results.push($('
').appendTo($('body').first()).addClass('updated-element').offset({ + top: top, + left: left + }).width($(node).width()).height($(node).height())); + } + return _results; + })(); + return setTimeout((function() { + var cover, _j, _len1, _results; + + _results = []; + for (_j = 0, _len1 = covers.length; _j < _len1; _j++) { + cover = covers[_j]; + _results.push($(cover).remove()); + } + return _results; + }), 2000); + } + } else if (_.isString(contents) || contents instanceof Element || contents instanceof RawHtml || contents instanceof $) { + return updateContents([contents]); + } else { + throw new Error("Unknown type for element contents: " + contents.constructor.name + " (accepted types: string, Element, RawHtml, jQuery object of single element, or array of the aforementioned)"); + } + }; + if (contents instanceof ObsArray) { + rx.autoSub(contents.onChange, function(_arg) { + var added, index, removed, toAdd; + + index = _arg[0], removed = _arg[1], added = _arg[2]; + elt.contents().slice(index, index + removed.length).remove(); + toAdd = toNodes(added); + if (index === elt.contents().length) { + return elt.append(toAdd); + } else { + return elt.contents().eq(index).before(toAdd); + } + }); + } else if (contents instanceof ObsCell) { + rx.autoSub(contents.onSet, function(_arg) { + var old, val; + + old = _arg[0], val = _arg[1]; + return updateContents(val); + }); + } else { + updateContents(contents); + } + } + for (key in attrs) { + if (key in specialAttrs) { + specialAttrs[key](elt, attrs[key], attrs, contents); + } + } + return elt; + }; + }; + tags = ['html', 'head', 'title', 'base', 'link', 'meta', 'style', 'script', 'noscript', 'body', 'body', 'section', 'nav', 'article', 'aside', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'h1', 'h6', 'header', 'footer', 'address', 'main', 'main', 'p', 'hr', 'pre', 'blockquote', 'ol', 'ul', 'li', 'dl', 'dt', 'dd', 'dd', 'figure', 'figcaption', 'div', 'a', 'em', 'strong', 'small', 's', 'cite', 'q', 'dfn', 'abbr', 'data', 'time', 'code', 'var', 'samp', 'kbd', 'sub', 'sup', 'i', 'b', 'u', 'mark', 'ruby', 'rt', 'rp', 'bdi', 'bdo', 'span', 'br', 'wbr', 'ins', 'del', 'img', 'iframe', 'embed', 'object', 'param', 'object', 'video', 'audio', 'source', 'video', 'audio', 'track', 'video', 'audio', 'canvas', 'map', 'area', 'area', 'map', 'svg', 'math', 'table', 'caption', 'colgroup', 'col', 'tbody', 'thead', 'tfoot', 'tr', 'td', 'th', 'form', 'fieldset', 'legend', 'fieldset', 'label', 'input', 'button', 'select', 'datalist', 'optgroup', 'option', 'select', 'datalist', 'textarea', 'keygen', 'output', 'progress', 'meter', 'details', 'summary', 'details', 'menuitem', 'menu']; + rxt.tags = _.object((function() { + var _j, _len1, _results; + + _results = []; + for (_j = 0, _len1 = tags.length; _j < _len1; _j++) { + tag = tags[_j]; + _results.push([tag, rxt.mktag(tag)]); + } + return _results; + })()); + rxt.rawHtml = function(html) { + return new RawHtml(html); + }; + rxt.importTags = function(x) { + return _(x != null ? x : _this).extend(rxt.tags); + }; + rxt.cast = function(opts, types) { + var key, newval, value; + + return _.object((function() { + var _results; + + _results = []; + for (key in opts) { + value = opts[key]; + newval = (function() { + switch (types[key]) { + case 'array': + if (value instanceof rx.ObsArray) { + return value; + } else if (_.isArray(value)) { + return new rx.DepArray(function() { + return value; + }); + } else if (value instanceof rx.ObsCell) { + return new rx.DepArray(function() { + return value.get(); + }); + } else { + throw new Error('Cannot cast to array: ' + value.constructor.name); + } + break; + case 'cell': + if (value instanceof rx.ObsCell) { + return value; + } else { + return bind(function() { + return value; + }); + } + break; + default: + return value; + } + })(); + _results.push([key, newval]); + } + return _results; + })()); + }; + rxt.cssify = function(map) { + var k, v; + + return ((function() { + var _results; + + _results = []; + for (k in map) { + v = map[k]; + if (v != null) { + _results.push("" + (_.str.dasherize(k)) + ": " + (_.isNumber(v) ? v + 'px' : v) + ";"); + } + } + return _results; + })()).join(' '); + }; + specialAttrs.style = function(elt, value) { + return setDynProp(elt, 'style', value, function(val) { + if (_.isString(val)) { + return val; + } else { + return rxt.cssify(val); + } + }); + }; + rxt.smushClasses = function(xs) { + return _(xs).chain().flatten().compact().value().join(' ').replace(/\s+/, ' ').trim(); + }; + specialAttrs["class"] = function(elt, value) { + return setDynProp(elt, 'class', value, function(val) { + if (_.isString(val)) { + return val; + } else { + return rxt.smushClasses(val); + } + }); + }; + } + rx.rxt = rxt; + return rx; + }; + + (function(root, factory, deps) { + var rx, _, _str; + + if ((typeof define !== "undefined" && define !== null ? define.amd : void 0) != null) { + return define(deps, factory); + } else if ((typeof module !== "undefined" && module !== null ? module.exports : void 0) != null) { + _ = require('underscore'); + _str = require('underscore.string'); + rx = factory(_, _str); + return module.exports = rx; + } else if ((root._ != null) && (root.$ != null)) { + return root.rx = factory(root._, void 0, root.$); + } else { + throw "Dependencies are not met for reactive: _ and $ not found"; + } + })(this, rxFactory, ['underscore', 'underscore.string', 'jquery']); + +}).call(this); diff --git a/ajax/libs/reactive-coffee/1.1.0/reactive-coffee.min.js b/ajax/libs/reactive-coffee/1.1.0/reactive-coffee.min.js new file mode 100644 index 000000000..4777142c5 --- /dev/null +++ b/ajax/libs/reactive-coffee/1.1.0/reactive-coffee.min.js @@ -0,0 +1 @@ +(function(){var a,b=[].slice,c={}.hasOwnProperty,d=function(a,b){function d(){this.constructor=a}for(var e in b)c.call(b,e)&&(a[e]=b[e]);return d.prototype=b.prototype,a.prototype=new d,a.__super__=b.prototype,a};a=function(a,c,e){var f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,$,_,ab,bb,cb,db,eb,fb,gb,hb,ib,jb=this;if(V={},M=0,L=function(){return M+=1},P=function(a,b){var c;if(!(b in a))throw new Error("object has no key "+b);return c=a[b],delete a[b],c},N=function(a,b,c){var d,e,f,g;for(d=f=0,g=a.length;g>f;d=++f)if(e=a[d],c(e)&&(b-=1)<0)return[e,d];return[null,-1]},F=function(a,b){return N(a,0,b)},J=function(b){var c,d,e,f,g,h;if(null==b&&(b=[]),d=null!=Object.create?Object.create(null):{},a.isArray(b))for(f=0,g=b.length;g>f;f++)h=b[f],c=h[0],e=h[1],d[c]=e;else for(c in b)e=b[c],d[c]=e;return d},$=function(a){var b,c,d,e;for(b=0,d=0,e=a.length;e>d;d++)c=a[d],b+=c;return b},i=V.DepMgr=function(){function a(){this.uid2src={},this.buffering=0,this.buffer=[]}return a.prototype.sub=function(a,b){return this.uid2src[a]=b},a.prototype.unsub=function(a){return P(this.uid2src,a)},a.prototype.transaction=function(a){var b,c,d,e,f;this.buffering+=1;try{c=a()}finally{if(this.buffering-=1,0===this.buffering){for(f=this.buffer,d=0,e=f.length;e>d;d++)(b=f[d])();this.buffer=[]}}return c},a}(),V._depMgr=C=new i,j=V.Ev=function(){function a(a){this.inits=a,this.subs=J()}return a.prototype.sub=function(a){var b,c,d,e,f;if(c=L(),null!=this.inits)for(f=this.inits(),d=0,e=f.length;e>d;d++)b=f[d],a(b);return this.subs[c]=a,C.sub(c,this),c},a.prototype.pub=function(a){var b,c,d,e,f=this;if(C.buffering)return C.buffer.push(function(){return f.pub(a)});d=this.subs,e=[];for(c in d)b=d[c],e.push(b(a));return e},a.prototype.unsub=function(a){return P(this.subs,a),C.unsub(a,this)},a.prototype.scoped=function(a,b){var c;c=this.sub(a);try{return b()}finally{this.unsub(c)}},a}(),V.skipFirst=function(a){var c;return c=!0,function(){var d;return d=1<=arguments.length?b.call(arguments,0):[],c?c=!1:a.apply(null,d)}},v=V.Recorder=function(){function b(){this.stack=[],this.isMutating=!1,this.isIgnoring=!1,this.onMutationWarning=new j}return b.prototype.record=function(b,c){var d,e;this.stack.length>0&&!this.isMutating&&a(this.stack).last().addNestedBind(b),this.stack.push(b),e=this.isMutating,this.isMutating=!1,d=this.isIgnoring,this.isIgnoring=!1;try{return c()}finally{this.isIgnoring=d,this.isMutating=e,this.stack.pop()}},b.prototype.sub=function(b){var c,d;return this.stack.length>0&&!this.isIgnoring?(d=a(this.stack).last(),c=b(d)):void 0},b.prototype.addCleanup=function(b){return this.stack.length>0?a(this.stack).last().addCleanup(b):void 0},b.prototype.mutating=function(a){var b;this.stack.length>0&&(console.warn("Mutation to observable detected during a bind context"),this.onMutationWarning.pub(null)),b=this.isMutating,this.isMutating=!0;try{return a()}finally{this.isMutating=b}},b.prototype.ignoring=function(a){var b;b=this.isIgnoring,this.isIgnoring=!0;try{return a()}finally{this.isIgnoring=b}},b}(),V._recorder=U=new v,V.asyncBind=A=function(a,b){var c;return c=new g(b,a),c.refresh(),c},V.bind=B=function(a){return A(null,function(){return this.done(this.record(a))})},V.lagBind=H=function(a,b,c){var d;return d=null,A(b,function(){var b=this;return null!=d&&clearTimeout(d),d=setTimeout(function(){return b.done(b.record(c))},a)})},V.postLagBind=Q=function(a,b){var c;return c=null,A(a,function(){var a,d,e,f=this;return e=this.record(b),d=e.val,a=e.ms,null!=c&&clearTimeout(c),c=setTimeout(function(){return f.done(d)},a)})},V.snap=function(a){return U.ignoring(a)},V.onDispose=function(a){return U.addCleanup(a)},V.autoSub=function(a,b){var c;return c=a.sub(b),V.onDispose(function(){return a.unsub(c)}),c},r=V.ObsCell=function(){function a(a){var b,c=this;this.x=a,this.x=null!=(b=this.x)?b:null,this.onSet=new j(function(){return[[null,c.x]]})}return a.prototype.get=function(){var a=this;return U.sub(function(b){return V.autoSub(a.onSet,function(){return b.refresh()})}),this.x},a}(),x=V.SrcCell=function(a){function b(){return eb=b.__super__.constructor.apply(this,arguments)}return d(b,a),b.prototype.set=function(a){var b=this;return U.mutating(function(){var c;return b.x!==a?(c=b.x,b.x=a,b.onSet.pub([c,a]),c):void 0})},b}(r),g=V.DepCell=function(a){function b(a,c){this.body=a,b.__super__.constructor.call(this,null!=c?c:null),this.refreshing=!1,this.nestedBinds=[],this.cleanups=[]}return d(b,a),b.prototype.refresh=function(){var a,b,c,d,e,f=this;return this.refreshing?void 0:(c=this.x,d=function(a){return f.x=a,f.onSet.pub([c,f.x])},e=null,b=!1,a={record:function(c){var g,h;if(!f.refreshing){if(f.disconnect(),g)throw new Error("this refresh has already recorded its dependencies");f.refreshing=!0,g=!0;try{h=U.record(f,function(){return c.call(a)})}finally{f.refreshing=!1}return b&&d(e),h}},done:function(a){return c!==a?f.refreshing?(b=!0,e=a):d(a):void 0}},this.body.call(a))},b.prototype.disconnect=function(){var a,b,c,d,e,f,g,h;for(g=this.cleanups,c=0,e=g.length;e>c;c++)(a=g[c])();for(h=this.nestedBinds,d=0,f=h.length;f>d;d++)b=h[d],b.disconnect();return this.nestedBinds=[],this.cleanups=[]},b.prototype.addNestedBind=function(a){return this.nestedBinds.push(a)},b.prototype.addCleanup=function(a){return this.cleanups.push(a)},b}(r),q=V.ObsArray=function(){function b(a,b){var c=this;this.xs=null!=a?a:[],this.diff=null!=b?b:V.basicDiff(),this.onChange=new j(function(){return[[0,[],c.xs]]}),this.indexed_=null}return b.prototype.all=function(){var b=this;return U.sub(function(a){return V.autoSub(b.onChange,function(){return a.refresh()})}),a.clone(this.xs)},b.prototype.raw=function(){var a=this;return U.sub(function(b){return V.autoSub(a.onChange,function(){return b.refresh()})}),this.xs},b.prototype.at=function(a){var b=this;return U.sub(function(c){return V.autoSub(b.onChange,function(b){var d,e,f;return e=b[0],f=b[1],d=b[2],e===a?c.refresh():void 0})}),this.xs[a]},b.prototype.length=function(){var a=this;return U.sub(function(b){return V.autoSub(a.onChange,function(a){var c,d,e;return d=a[0],e=a[1],c=a[2],e.length!==c.length?b.refresh():void 0})}),this.xs.length},b.prototype.map=function(a){var b;return b=new p,V.autoSub(this.onChange,function(c){var d,e,f;return e=c[0],f=c[1],d=c[2],b.realSplice(e,f.length,d.map(a))}),b},b.prototype.indexed=function(){var a=this;return null==this.indexed_&&(this.indexed_=new n,V.autoSub(this.onChange,function(b){var c,d,e;return d=b[0],e=b[1],c=b[2],a.indexed_.realSplice(d,e.length,c)})),this.indexed_},b.prototype.concat=function(a){return V.concat(this,a)},b.prototype.realSplice=function(a,b,c){var d;return d=this.xs.splice.apply(this.xs,[a,b].concat(c)),this.onChange.pub([a,d,c])},b.prototype._update=function(a,b){var c,d,e,f,g,h,i,j,k,l,m,n;for(null==b&&(b=this.diff),g=this.xs,e=[0,g.length,a],j=null,i=null!=b?null!=(m=O(g.length,a,b(g,a)))?m:[e]:[e],n=[],k=0,l=i.length;l>k;k++)h=i[k],f=h[0],d=h[1],c=h[2],n.push(this.realSplice(f,d,c));return n},b}(),w=V.SrcArray=function(c){function e(){return fb=e.__super__.constructor.apply(this,arguments)}return d(e,c),e.prototype.spliceArray=function(a,b,c){var d=this;return U.mutating(function(){return d.realSplice(a,b,c)})},e.prototype.splice=function(){var a,c,d;return d=arguments[0],c=arguments[1],a=3<=arguments.length?b.call(arguments,2):[],this.spliceArray(d,c,a)},e.prototype.insert=function(a,b){return this.splice(b,0,a)},e.prototype.remove=function(b){var c;return c=a(this.raw()).indexOf(b),c>=0?this.removeAt(c):void 0},e.prototype.removeAt=function(a){return this.splice(a,1)},e.prototype.push=function(a){return this.splice(this.length(),0,a)},e.prototype.put=function(a,b){return this.splice(a,1,b)},e.prototype.replace=function(a){return this.spliceArray(0,this.length(),a)},e.prototype.update=function(a){var b=this;return U.mutating(function(){return b._update(a)})},e}(q),p=V.MappedDepArray=function(a){function b(){return gb=b.__super__.constructor.apply(this,arguments)}return d(b,a),b}(q),n=V.IndexedDepArray=function(c){function e(b,c){var d,f,g=this;null==b&&(b=[]),e.__super__.constructor.call(this,b,c),this.is=function(){var a,b,c,e;for(c=this.xs,e=[],d=a=0,b=c.length;b>a;d=++a)f=c[d],e.push(V.cell(d));return e}.call(this),this.onChange=new j(function(){return[[0,[],a.zip(g.xs,g.is)]]})}return d(e,c),e.prototype.map=function(a){var b;return b=new o,V.autoSub(this.onChange,function(c){var d,e,f,g,h;return g=c[0],h=c[1],e=c[2],b.realSplice(g,h.length,function(){var b,c,g,h;for(h=[],b=0,c=e.length;c>b;b++)g=e[b],d=g[0],f=g[1],h.push(a(d,f));return h}())}),b},e.prototype.realSplice=function(c,d,e){var f,g,h,i,j,k,l,m,n;for(i=(l=this.xs).splice.apply(l,[c,d].concat(b.call(e))),m=this.is.slice(c+d),h=j=0,k=m.length;k>j;h=++j)f=m[h],f.set(c+e.length+h);return g=function(){var a,b,d;for(d=[],f=a=0,b=e.length;b>=0?b>a:a>b;f=b>=0?++a:--a)d.push(V.cell(c+f));return d}(),(n=this.is).splice.apply(n,[c,d].concat(b.call(g))),this.onChange.pub([c,i,a.zip(e,g)])},e}(q),o=V.IndexedMappedDepArray=function(a){function b(){return hb=b.__super__.constructor.apply(this,arguments)}return d(b,a),b}(n),f=V.DepArray=function(a){function b(a,c){var d=this;this.f=a,b.__super__.constructor.call(this,[],c),V.autoSub(B(function(){return d.f()}).onSet,function(a){var b,c;return b=a[0],c=a[1],d._update(c)})}return d(b,a),b}(q),m=V.IndexedArray=function(a){function b(a){this.xs=a}return d(b,a),b.prototype.map=function(a){var b;return b=new p,V.autoSub(this.xs.onChange,function(c){var d,e,f;return e=c[0],f=c[1],d=c[2],b.realSplice(e,f.length,d.map(a))}),b},b}(f),V.concat=function(){var a,c,d,e;return d=1<=arguments.length?b.call(arguments,0):[],e=new p,a=function(){var a,b,e;for(e=[],a=0,b=d.length;b>a;a++)c=d[a],e.push(0);return e}(),d.map(function(b,c){return V.autoSub(b.onChange,function(b){var d,f,g,h;return f=b[0],g=b[1],d=b[2],h=$(a.slice(0,c)),a[c]+=d.length-g.length,e.realSplice(h+f,g.length,d)})}),e},l=V.FakeSrcCell=function(a){function b(a,b){this._getter=a,this._setter=b}return d(b,a),b.prototype.get=function(){return this._getter()},b.prototype.set=function(a){return this._setter(a)},b}(x),k=V.FakeObsCell=function(a){function b(a){this._getter=a}return d(b,a),b.prototype.get=function(){return this._getter()},b}(r),z=V.MapEntryCell=function(a){function b(a,b){this._map=a,this._key=b}return d(b,a),b.prototype.get=function(){return this._map.get(this._key)},b.prototype.set=function(a){return this._map.put(this._key,a)},b}(l),t=V.ObsMapEntryCell=function(a){function b(a,b){this._map=a,this._key=b}return d(b,a),b.prototype.get=function(){return this._map.get(this._key)},b}(k),s=V.ObsMap=function(){function b(a){this.x=null!=a?a:{},this.onAdd=new j(function(){var b,c,d;d=[];for(b in a)c=a[b],d.push([b,c]);return d}),this.onRemove=new j,this.onChange=new j}return b.prototype.get=function(a){var b=this;return U.sub(function(c){return V.autoSub(b.onAdd,function(b){var d,e;return d=b[0],e=b[1],a===d?c.refresh():void 0})}),U.sub(function(c){return V.autoSub(b.onChange,function(b){var d,e,f;return e=b[0],d=b[1],f=b[2],a===e?c.refresh():void 0})}),U.sub(function(c){return V.autoSub(b.onRemove,function(b){var d,e;return e=b[0],d=b[1],a===e?c.refresh():void 0})}),this.x[a]},b.prototype.all=function(){var b=this;return U.sub(function(a){return V.autoSub(b.onAdd,function(){return a.refresh()})}),U.sub(function(a){return V.autoSub(b.onChange,function(){return a.refresh()})}),U.sub(function(a){return V.autoSub(b.onRemove,function(){return a.refresh()})}),a.clone(this.x)},b.prototype.realPut=function(a,b){var c;return a in this.x?(c=this.x[a],this.x[a]=b,this.onChange.pub([a,c,b]),c):(this.x[a]=b,void this.onAdd.pub([a,b]))},b.prototype.realRemove=function(a){var b;return b=P(this.x,a),this.onRemove.pub([a,b]),b},b.prototype.cell=function(a){return new t(this,a)},b}(),y=V.SrcMap=function(a){function b(){return ib=b.__super__.constructor.apply(this,arguments)}return d(b,a),b.prototype.put=function(a,b){var c=this;return U.mutating(function(){return c.realPut(a,b)})},b.prototype.remove=function(a){var b=this;return U.mutating(function(){return b.realRemove(a)})},b.prototype.cell=function(a){return new z(this,a)},b}(s),h=V.DepMap=function(a){function b(a){this.f=a,b.__super__.constructor.call(this),V.autoSub(new g(this.f).onSet,function(a){var b,c,d,e,f;c=a[0],e=a[1];for(b in c)d=c[b],b in e||this.realRemove(b);f=[];for(b in e)d=e[b],f.push(this.x[b]!==d?this.realPut(b,d):void 0);return f})}return d(b,a),b}(s),V.liftSpec=function(b){var c,d,e;return a.object(function(){var f,g,h,i;for(h=Object.getOwnPropertyNames(b),i=[],f=0,g=h.length;g>f;f++)c=h[f],e=b[c],null!=e&&(e instanceof V.ObsMap||e instanceof V.ObsCell||e instanceof V.ObsArray)||(d=a.isFunction(e)?null:a.isArray(e)?"array":"cell",i.push([c,{type:d,val:e}]));return i}())},V.lift=function(a,b){var c,d;null==b&&(b=V.liftSpec(a));for(c in b)d=b[c],a[c]=function(){switch(d.type){case"cell":return V.cell(a[c]);case"array":return V.array(a[c]);case"map":return V.map(a[c]);default:return a[c]}}();return a},V.unlift=function(b){var c,d;return a.object(function(){var a;a=[];for(c in b)d=b[c],a.push([c,d instanceof V.ObsCell?d.get():d instanceof V.ObsArray?d.all():d]);return a}())},V.reactify=function(c,d){var e,f,g,h;return a.isArray(c)?(e=V.array(a.clone(c)),Object.defineProperties(c,a.object(function(){var d,g,h,i;for(h=a.functions(e),i=[],d=0,g=h.length;g>d;d++)f=h[d],"length"!==f&&i.push(function(a){var d,f,g;return d=c[a],f=function(){var f,g,h;return f=1<=arguments.length?b.call(arguments,0):[],null!=d&&(g=d.call.apply(d,[c].concat(b.call(f)))),(h=e[a]).call.apply(h,[e].concat(b.call(f))),g},g={configurable:!0,enumerable:!1,value:f,writable:!0},[a,g]}(f));return i}())),c):Object.defineProperties(c,a.object(function(){var a;a=[];for(g in d)h=d[g],a.push(function(a,c){var d,e,f,g,h;switch(d=null,c.type){case"cell":e=V.cell(null!=(g=c.val)?g:null),d={configurable:!0,enumerable:!0,get:function(){return e.get()},set:function(a){return e.set(a)}};break;case"array":f=V.reactify(null!=(h=c.val)?h:[]),d={configurable:!0,enumerable:!0,get:function(){return f.raw(),f},set:function(a){return f.splice.apply(f,[0,f.length].concat(b.call(a))),f}};break;default:throw new Error("Unknown observable type: "+type)}return[a,d]}(g,h));return a}()))},V.autoReactify=function(b){var c,d,e;return V.reactify(b,a.object(function(){var f,g,h,i;for(h=Object.getOwnPropertyNames(b),i=[],f=0,g=h.length;g>f;f++)c=h[f],e=b[c],e instanceof s||e instanceof r||e instanceof q||(d=a.isFunction(e)?null:a.isArray(e)?"array":"cell",i.push([c,{type:d,val:e}]));return i}()))},a.extend(V,{cell:function(a){return new x(a)},array:function(a,b){return new w(a,b)},map:function(a){return new y(a)}}),V.flatten=function(b){return new f(function(){var c;return a(function(){var a,d,e;for(e=[],a=0,d=b.length;d>a;a++)c=b[a],e.push(c instanceof q?c.raw():c instanceof r?c.get():c);return e}()).chain().flatten(!0).filter(function(a){return null!=a}).value()})},G=function(b){var c;return c=a.flatten(b),V.cellToArray(B(function(){return a.flatten(b)}))},V.cellToArray=function(a,b){return new f(function(){return a.get()},b)},V.basicDiff=function(a){return null==a&&(a=V.smartUidify),function(b,c){var d,e,f,g,h,i,j;for(e=J(function(){var c,e,g;for(g=[],d=c=0,e=b.length;e>c;d=++c)f=b[d],g.push([a(f),d]);return g}()),j=[],g=0,h=c.length;h>g;g++)f=c[g],j.push(null!=(i=e[a(f)])?i:-1);return j}},V.uidify=function(a){var b;return null!=(b=a.__rxUid)?b:Object.defineProperty(a,"__rxUid",{enumerable:!1,value:L()}).__rxUid},V.smartUidify=function(b){return a.isObject(b)?V.uidify(b):JSON.stringify(b)},O=function(b,c,d){var e,f,g,h,i,j;if(h=function(){var a,b,c;for(c=[],a=0,b=d.length;b>a;a++)f=d[a],f>=0&&c.push(f);return c}(),a.some(function(){var a,b,c;for(c=[],f=a=0,b=h.length-1;b>=0?b>a:a>b;f=b>=0?++a:--a)c.push(h[f+1]-h[f]<=0);return c}()))return null;for(j=[],g=-1,f=0;f