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

5.0.0 from Develop #2

Merged
merged 21 commits into from
Nov 10, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
reference type updated
  • Loading branch information
skclusive committed Sep 29, 2020
commit 8ee38ce2019f69956a2de7c2e63445359a4bdf04
22 changes: 19 additions & 3 deletions src/StateTree/Combine/ReferenceType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,22 @@ internal StoredReference(StoreType type, object value, IType targetType)

_resolvedValue = ComputedValue<object>.From(() =>
{
var identifier = Value?.ToString();

if (string.IsNullOrWhiteSpace(identifier))
{
return null;
}

// reference was initialized with the identifier of the target
var target = Node.Root.IdentifierCache?.Resolve(TargetType, Value.ToString());
var target = Node.Root.IdentifierCache?.Resolve(TargetType, identifier);

if (target == null)
{
throw new Exception($"Failed to resolve reference '{Value}' to type '{TargetType.Name}' (from node: {Node.Path})");
throw new Exception($"Failed to resolve reference '{identifier}' to type '{TargetType.Name}' (from node: {Node.Path})");
}

return target.Value;
return target?.Value;
});
}

Expand Down Expand Up @@ -167,6 +174,15 @@ public override INode Instantiate(INode parent, string subpath, IEnvironment env

public override INode Reconcile(INode current, object newValue)
{
// custom changes start
if (newValue.IsStateTreeNode())
{
var node = newValue.GetStateTreeNode();

newValue = StateTreeUtils.GetPropertyValue(node.StoredValue, node.IdentifierAttribute);
}
//custom changes end

if (current.Type == this)
{
var targetMode = newValue.IsStateTreeNode() ? StoreType.Object : StoreType.Identifier;
Expand Down