UNPKG

janus

Version:

the two-faced application library-framework

55 lines (45 loc) 1.58 kB
// Generated by CoffeeScript 1.12.2 (function() { var Base, SumFold, 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; SumFold = (function(superClass) { extend(SumFold, superClass); function SumFold(list) { var i, len, ref, sum, x; SumFold.__super__.constructor.call(this); sum = 0; ref = list.list; for (i = 0, len = ref.length; i < len; i++) { x = ref[i]; sum += x; } this._varying = new Varying(sum); this.listenTo(list, 'added', (function(_this) { return function(obj) { _this._varying.set(_this._varying.get() + (obj != null ? obj : 0)); }; })(this)); this.listenTo(list, 'removed', (function(_this) { return function(obj) { _this._varying.set(_this._varying.get() - (obj != null ? obj : 0)); }; })(this)); } SumFold.sum = function(list) { return Varying.managed((function() { return new SumFold(list, function(x, y) { return x < y; }); }), function(incl) { return incl._varying; }); }; return SumFold; })(Base); module.exports = { SumFold: SumFold }; }).call(this);