Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S.value multiple updates with no listeners fail #25

Open
webstrand opened this issue May 15, 2019 · 1 comment · May be fixed by #44
Open

S.value multiple updates with no listeners fail #25

webstrand opened this issue May 15, 2019 · 1 comment · May be fixed by #44

Comments

@webstrand
Copy link

webstrand commented May 15, 2019

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!;
        }
@Qix-
Copy link

Qix- commented Nov 25, 2019

Just ran into this ourselves.

This is also hotfixed by always setting this.log = new Log() in the DataNode constructor. It looks like an optimization to reduce memory usage (❤️ always appreciated) by not allocating a new Log object for all data signals that may not be used in computations, but that gets bugged when no computations actually use the value.

@adamhaile any chance of getting a fix for this? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants