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

Fixes ShapeResult Copy() #6940

Merged
merged 1 commit into from
Aug 20, 2020
Merged

Fixes ShapeResult Copy() #6940

merged 1 commit into from
Aug 20, 2020

Conversation

jtkech
Copy link
Member

@jtkech jtkech commented Aug 19, 2020

Currently we have

public ShapeResult Copy<TModel>(string shapeType, TModel model) where TModel : class
{
    return Dynamic(shapeType, ctx => ctx.ShapeFactory.CreateAsync(shapeType, model));
}

Which always fails here

public ShapeResult Dynamic(string shapeType, Func<dynamic, Task> initializeAsync)
{
    return Factory(shapeType,
        async ctx =>
        {
            dynamic shape = await ctx.ShapeFactory.CreateAsync(shapeType);
            await initializeAsync(shape); <= ALWAYS FAILS HERE
            return shape;
        });
}

Because ctx => ctx.ShapeFactory.CreateAsync(shapeType, model)) is more like a shapeBuilder delegate than an initializeAsync delegate, so, fixed by using instead

public ShapeResult Copy<TModel>(string shapeType, TModel model) where TModel : class
{
    return Factory(shapeType, ctx => ctx.ShapeFactory.CreateAsync(shapeType, model));
}

// The Factory signature being
public ShapeResult Factory(string shapeType, Func<IBuildShapeContext, ValueTask<IShape>> shapeBuilder)

@agriffard agriffard merged commit 713a321 into dev Aug 20, 2020
@agriffard agriffard deleted the jtkech/shapeCopy branch August 20, 2020 08:07
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 this pull request may close these issues.

3 participants