Skip to content

Great project #61

@johnhamm

Description

@johnhamm

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

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