Skip to content

Add support for callCached on GET methods. #12

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

Merged
merged 5 commits into from
Jan 10, 2017

Conversation

dborovic
Copy link
Collaborator

@dborovic dborovic commented Jan 5, 2017

Resolves #8
Accidentally called branch issue-9 which is wrong.

@@ -17,12 +20,29 @@ namespace Endpoints {
return call.then(response => response.data);
}

static callCached<TView>(endpoint: IEndpoint, data) {
if (this.endpointCache[endpoint.toString()] == null) {
return this.call(endpoint, data).then(result => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to do this.call<TView>(endpoint, data) here?

@@ -17,12 +20,29 @@ namespace Endpoints {
return call.then(response => response.data);
}

static callCached<TView>(endpoint: IEndpoint, data) {
if (this.endpointCache[endpoint.toString()] == null) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to extract endpoint.toString() to a variable here. Perhaps cacheKey? And reuse below?

@@ -12,6 +12,9 @@ public class Config
public string EndpointsOutputDirectory { get; set; }
= "Endpoints";

public bool EndpointsSupportCaching { get; set; }
= true;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we now have folks using it, can we default to false for all new features please?

@@ -72,6 +93,13 @@ public void WriteServiceObjectToBlock(TypeScriptBlock serviceBlock, WebApiContro
var interfaceWithCallFullName = $"{Config.EndpointsNamespace}.{webApiController.Name}.I{actionName}WithCall";
var endpointFullName = $"{Config.EndpointsNamespace}.{webApiController.Name}.{actionName}";

var cachedBlock = Config.EndpointsSupportCaching &&
string.Equals(verb.Verb, "GET", StringComparison.InvariantCultureIgnoreCase)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use WebApiHttpVerb.Get here and compare with the action verb?

@@ -72,6 +93,13 @@ public void WriteServiceObjectToBlock(TypeScriptBlock serviceBlock, WebApiContro
var interfaceWithCallFullName = $"{Config.EndpointsNamespace}.{webApiController.Name}.I{actionName}WithCall";
var endpointFullName = $"{Config.EndpointsNamespace}.{webApiController.Name}.{actionName}";

var cachedBlock = Config.EndpointsSupportCaching &&
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer if we make this a boolean variable first, and then do a if (boolean) block.AddAndUseBlock below and get rid of the newly added AddBlock(block) methods just for consistency. We could then begin a discussion if we need to support the other format? I dislike null checks. Control flows without null is better I think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That won't work because Fluent way of writing this will end the block and the function will be outside of proper scope

.AddAndUseBlock($"call<TView>({callArgumentDefinition})", isFunctionBlock: false, terminationString: ",")
.AddStatement($"return {Config.ServiceName}.call<TView>(this, {callArgumentValue});")
.Parent
.AddBlock(cachedBlock);
Copy link
Owner

@greymind greymind Jan 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Save this to a variable and do a if (boolean) variable.AddAndUseBlock( /*create cached block here */)?

Copy link
Owner

@greymind greymind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please adjust based on suggestions! Thanks!

@greymind greymind merged commit 576e676 into master Jan 10, 2017
@greymind greymind deleted the issue-9-add-call-cached-support branch January 25, 2019 13:00
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.

2 participants