UNPKG

janus

Version:

the two-faced application library-framework

69 lines (59 loc) 2.01 kB
// Generated by CoffeeScript 1.12.2 (function() { var Base, IncludesFold, Varying, 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; Base = require('../../core/base').Base; IncludesFold = (function(superClass) { extend(IncludesFold, superClass); function IncludesFold(list, x) { IncludesFold.__super__.constructor.call(this); this._varying = new Varying(false); this.listenTo(list, 'added', (function(_this) { return function(obj) { if (obj === _this._value) { _this._count += 1; _this._varying.set(true); } }; })(this)); this.listenTo(list, 'removed', (function(_this) { return function(obj) { if (obj === _this._value) { _this._count -= 1; if (_this._count === 0) { _this._varying.set(false); } } }; })(this)); this.reactTo(Varying.of(x), (function(_this) { return function(value) { var i, len, ref; _this._value = value; _this._count = 0; ref = list.list; for (i = 0, len = ref.length; i < len; i++) { x = ref[i]; if (x === value) { _this._count += 1; } } _this._varying.set(_this._count > 0); }; })(this)); } IncludesFold.includes = function(list, x) { return Varying.managed((function() { return new IncludesFold(list, x); }), function(incl) { return incl._varying; }); }; return IncludesFold; })(Base); module.exports = { IncludesFold: IncludesFold }; }).call(this);