UNPKG

janus

Version:

the two-faced application library-framework

166 lines (140 loc) 4.81 kB
// Generated by CoffeeScript 1.12.2 (function() { var DerivedList, Enumeration, IndexList, KeySet, Map, Set, Varying, _dynamic, deepGet, ref, traverse, extend = 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; }, hasProp = {}.hasOwnProperty; Varying = require('../core/varying').Varying; DerivedList = require('../collection/list').DerivedList; Set = require('../collection/set').Set; Map = require('./map').Map; ref = require('../util/util'), traverse = ref.traverse, deepGet = ref.deepGet; KeySet = (function(superClass) { extend(KeySet, superClass); function KeySet(parent1) { this.parent = parent1; KeySet.__super__.constructor.call(this); this._list.add(Enumeration.map_(this.parent)); this.listenTo(this.parent, 'changed', (function(_this) { return function(key, newValue, oldValue) { if ((newValue != null) && (oldValue == null)) { Set.prototype.add.call(_this, key); } else if ((oldValue != null) && (newValue == null)) { Set.prototype.remove.call(_this, key); } }; })(this)); } KeySet.prototype.mapPairs = function(f) { return this.flatMap((function(_this) { return function(k) { return Varying.mapAll(f, new Varying(k), _this.parent.get(k)); }; })(this)); }; KeySet.prototype.flatMapPairs = function(f) { return this.flatMap((function(_this) { return function(k) { return Varying.flatMapAll(f, new Varying(k), _this.parent.get(k)); }; })(this)); }; KeySet.prototype.add = void 0; KeySet.prototype.remove = void 0; return KeySet; })(Set); IndexList = (function(superClass) { var update; extend(IndexList, superClass); update = function(parent, self) { return function() { var i, idx, j, length, ourLength, ref1, ref2, ref3, ref4; length = parent.length_; ourLength = self.length_; if (length > ourLength) { for (idx = i = ref1 = ourLength, ref2 = length; ref1 <= ref2 ? i < ref2 : i > ref2; idx = ref1 <= ref2 ? ++i : --i) { self._add(idx); } } else if (length < ourLength) { for (idx = j = ref3 = ourLength, ref4 = length; j > ref4; idx = j += -1) { self._removeAt(idx - 1); } } }; }; function IndexList(parent1) { var updater; this.parent = parent1; IndexList.__super__.constructor.call(this); updater = update(this.parent, this); this.listenTo(this.parent, 'added', updater); this.listenTo(this.parent, 'removed', updater); updater(); } IndexList.prototype.mapPairs = function(f) { return this.flatMap((function(_this) { return function(idx) { return Varying.mapAll(f, new Varying(idx), _this.parent.at(idx)); }; })(this)); }; IndexList.prototype.flatMapPairs = function(f) { return this.flatMap((function(_this) { return function(idx) { return Varying.flatMapAll(f, new Varying(idx), _this.parent.at(idx)); }; })(this)); }; return IndexList; })(DerivedList); _dynamic = function(suffix) { return function(obj, options) { var type; type = obj.isMappable === true ? 'list' : obj.isMap === true ? 'map' : void 0; return Enumeration[type + suffix](obj, options); }; }; Enumeration = { get_: _dynamic('_'), get: _dynamic(''), map_: function(map) { var ptr, result, scanMap; result = []; scanMap = (function(_this) { return function(map) { return traverse(map.data, function(key) { var joined; joined = key.join('.'); if (!(result.indexOf(joined) >= 0)) { return result.push(joined); } }); }; })(this); ptr = map; while (ptr != null) { scanMap(ptr); ptr = ptr._parent; } return result; }, map: function(map, options) { return new KeySet(map, options); }, list_: function(list) { var i, idx, ref1, results; results = []; for (idx = i = 0, ref1 = list.length_; 0 <= ref1 ? i < ref1 : i > ref1; idx = 0 <= ref1 ? ++i : --i) { results.push(idx); } return results; }, list: function(list) { return new IndexList(list); } }; module.exports = { KeySet: KeySet, IndexList: IndexList, Enumeration: Enumeration }; }).call(this);