Why is getvalueof() called multiple times for each call to notifyclients()?

Luke Stark's icon

I've got a js object that holds an array and defines getvalueof() and setvalueof() so I can persist to a pattr.

It works. No problem, but I noticed that when I call notifyclients() my getvalueof() method is called multiple times. I'm not sure why.

inlets = 1;
outlets = 1;

var saved_data = [];

function list(a) {
    saved_data.push( a );
    notifyclients();
    outlet(0, a);
}

function showall() {
    for (var i in saved_data) {
        post(saved_data[i] + "n");
    }
}

function clear() {
    saved_data = [];
    notifyclients();
}

function getvalueof() {
    post("Saving.n");
    return saved_data
}

function setvalueof() {
    post("Restoring.n");
    restored_data = arrayfromargs(arguments);
    saved_data = restored_data;
    post("Restored.n");
}

Max Patch
Copy patch and select New From Clipboard in Max.

Here's a simple patch illustrating the behavior:

It's really bugging me. I can't tell if this is normal of if I'm missing some poor patching I did somewhere.

When I click on one of the numeric messages to be stored, getvalueof() is called 3 times?!

I must be doing something wrong. Opinions?

amounra's icon

I don't think you're doing anything wrong, I think that's just the way it is. I'd love to know why, though.

Luke Stark's icon

Not exactly solving the mystery, but I'm glad I'm not the only one experiencing it. Thanks for the responses!