Repeated diamonds shape

Warp9 was designed to avoid common pitfalls related to reactivity, so it is no surprise that it doesn't suffer from repeated diamonds shape problem.

Details Knockout Reactive Coffee Warp9

The target update rate doesn't depend on the diamonds count and is updates only once per each source update.

JS

var diamonds = new warp9.Cell("1");
var result = new warp9.Cell(1);
var dispose, updates;

warp9.render(placeholder, ["div",
    ["div",
        ["label", {"for": "d"}, "Enter number of diamonds:"],
        ["input-text", {"id": "d"}, diamonds],
        ["button", {"!click": function(){
            if (dispose) dispose();
            if (parseInt(diamonds.get())>0) {
                var source = new warp9.Cell();
                var target = repeatDiamondShape(source, parseInt(diamonds.get()));
                updates = 0;
                dispose = target.onSet(function(){
                    result.set(++updates);
                });
                source.set(2);
            } else result.unset();
        }}, "Calc updates"]
    ],
    result.lift(function(result){
        return ["span", "Expected one update & got " + result]
    }).coalesce(["span", "Should be an integer above 0"])
]);

function repeatDiamondShape(seed, n) {
    if (n==0) return seed;
    var s1 = warp9.do(function(){ return seed.get() + 1; });
    var s2 = warp9.do(function(){ return seed.get() + 1; });
    return repeatDiamondShape(warp9.do(function(){
        return s1.get() + s2.get();
    }), n-1);
}