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

Great project #61

Open
johnhamm opened this issue Oct 17, 2021 · 0 comments
Open

Great project #61

johnhamm opened this issue Oct 17, 2021 · 0 comments

Comments

@johnhamm
Copy link

johnhamm commented Oct 17, 2021

I'm a huge fan of mobx, so finding this library for Blazor makes me happy.

I'm new to Cortex.net and trying to understand why Computed seems to be recomputing a property when none of the data used in the previous computation has changed. Am I missing something?

using Cortex.Net.Api;

var test = new Person { FirstName = "John", LastName = "Doe" };
Console.WriteLine("1: " + test.FullName + " " + test.IsAJohn);

test.LastName = "Smith";

Console.WriteLine("2: " + test.FullName + " " + test.IsAJohn);
Console.WriteLine("3: " + test.FullName + " " + test.IsAJohn); // why compute again?

test.FirstName = "David";
Console.WriteLine("4: " + test.FullName + " " + test.IsAJohn);

[Observable]
public class Person
{
    public string? FirstName { get; set; }
    public string? LastName { get; set; }

    [Computed]
    public string FullName
    {
        get
        {
            Console.WriteLine("Computing FullName");
            return FirstName + " " + LastName;
        }
    }

    [Computed]
    public string IsAJohn
    {
        get
        {
            Console.WriteLine("Computing IsAJohn");
            return FirstName == "John" ? "Yep" : "Nope";
        }
    }    
}

Outputs:

Computing FullName
Computing IsAJohn
1: John Doe Yep
Computing FullName
Computing IsAJohn
2: John Smith Yep
Computing FullName
Computing IsAJohn
3: John Smith Yep
Computing FullName
Computing IsAJohn
4: David Smith Nope
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

No branches or pull requests

1 participant