Skip to content

S.value multiple updates with no listeners fail #25

@webstrand

Description

@webstrand

If you create an S.value and update it multiple times before attaching any listeners, the Value erroneously reports conflicting values.

var foo = S.value(100);
foo(200); // Succeeds
foo(300);
// Error: conflicting values: 300 is not the same as 200

I believe this happens, because on line 267 the DataNode does not cause to RootClock to tick if it has no listeners. So S.value's age is equal to the RootClock.time causing the fault.

A fix would be to preserve the age of the S.value when RunningClock == null and no listeners.

        if (arguments.length === 0) {
            return node.current();
        } 
        else if(RunningClock === null && node.log === null) {
            return current = node.next(update!);
        } else {
            var same = eq ? eq(current, update!) : current === update;
            if (!same) {
                var time = RootClock.time;
                if (age === time) 
                    throw new Error("conflicting values: " + update + " is not the same as " + current);
                age = time;
                current = update!;
                node.next(update!);
            }
            return update!;
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions