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

Replace AddressStateMap with IImmutableDictionary<Address, object> #98

Open
dahlia opened this issue Feb 22, 2019 · 2 comments

Comments

Projects
2 participants
@dahlia
Copy link
Member

commented Feb 22, 2019

The current implementation of AddressStateMap is just a thin wrapper around ImmutableDictionary<Address, object>, and implements IImmutableDictionary<Address, object> as well at a time. This was intended to mimic typedef IImmutableDictionary<Address, object> AddresStateMap; in C#. (Although C# allows using AddresStateMap = IImmutable<Address, object>;, the alias is scoped to only a file.) However, as AddressStateMap is not completely equivalent to IImmutableDictionary<Address, object> but only a subtype of it, it tends to cast things up and down, which leads runtime type unsafety. For instance, when we implement a IAction.Execute() method, it looks like:

public AddressStateMap Execute(IActionContext context)
{
    AddressStateMap states = context.PreviousStates;
    IImmutableDictionary<Address, object> newStates =
        states.SetItem(context.To, "new value");
    return (AddressStateMap) newStates;  // downcast
}

If we completely replace AddressStateMap with IImmutableDictionary<Address, object> it would look like instead:

public AddressStateMap Execute(IActionContext context)
{
    IImmutableDictionary<Address, object> states = context.PreviousStates;
    IImmutableDictionary<Address, object> newStates =
        states.SetItem(context.To, "new value");
    return newStates;  // no cast
}

@longfin longfin added this to To do in comuka-20190223 Feb 23, 2019

@dahlia dahlia referenced this issue Mar 8, 2019

Merged

Refactor the interface for actions updating states #121

4 of 5 tasks complete

@dahlia dahlia self-assigned this Mar 9, 2019

@longfin

This comment has been minimized.

Copy link
Member

commented Mar 20, 2019

@dahlia Is this still a valid issue?

@dahlia

This comment has been minimized.

Copy link
Member Author

commented Mar 20, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.