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.


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

warp9.render(placeholder, ["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(){
            } else result.unset();
        }}, "Calc updates"]
        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 ={ return seed.get() + 1; });
    var s2 ={ return seed.get() + 1; });
    return repeatDiamondShape({
        return s1.get() + s2.get();
    }), n-1);