Skip to content

Commit 349c35b

Browse files
committed
Comment related changes
1 parent 7c8a230 commit 349c35b

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

src/WebApiTestApplication/Scripts/Endpoints/Service.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@ namespace Endpoints {
2121
}
2222

2323
static callCached<TView>(endpoint: IEndpoint, data) {
24-
if (this.endpointCache[endpoint.toString()] == null) {
25-
return this.call(endpoint, data).then(result => {
26-
this.endpointCache[endpoint.toString()] = result;
27-
return this.endpointCache[endpoint.toString()];
24+
var cacheKey = endpoint.toString();
25+
26+
if (this.endpointCache[cacheKey] == null) {
27+
return this.call<TView>(endpoint, data).then(result => {
28+
this.endpointCache[cacheKey] = result;
29+
return this.endpointCache[cacheKey];
2830
});
2931
}
3032

3133
const deferred = this.$q.defer();
32-
deferred.resolve(this.endpointCache[endpoint.toString()]);
34+
deferred.resolve(this.endpointCache[cacheKey]);
3335
return deferred.promise;
3436
}
3537

src/WebApiToTypeScript/Config/Config.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class Config
1313
= "Endpoints";
1414

1515
public bool EndpointsSupportCaching { get; set; }
16-
= true;
16+
= false;
1717

1818
public string EndpointsFileName { get; set; }
1919
= "Endpoints.ts";

src/WebApiToTypeScript/Endpoints/AngularEndpointsService.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,18 @@ public TypeScriptBlock CreateServiceBlock()
3131
serviceBlock
3232
.Parent
3333
.AddAndUseBlock("static callCached<TView>(endpoint: IEndpoint, data)")
34-
.AddAndUseBlock("if (this.endpointCache[endpoint.toString()] == null)")
35-
.AddAndUseBlock("return this.call(endpoint, data).then(result =>", isFunctionBlock: true,
34+
.AddStatement("var cacheKey = endpoint.toString();")
35+
.AddAndUseBlock("if (this.endpointCache[cacheKey] == null)")
36+
.AddAndUseBlock("return this.call<TView>(endpoint, data).then(result =>", isFunctionBlock: true,
3637
terminationString: ";")
37-
.AddStatement("this.endpointCache[endpoint.toString()] = result;")
38-
.AddStatement("return this.endpointCache[endpoint.toString()];")
38+
.AddStatement("this.endpointCache[cacheKey] = result;")
39+
.AddStatement("return this.endpointCache[cacheKey];")
3940
.Parent
4041
.Parent
4142
.AddStatement("const deferred = this.$q.defer();")
42-
.AddStatement("deferred.resolve(this.endpointCache[endpoint.toString()]);")
43+
.AddStatement("deferred.resolve(this.endpointCache[cacheKey]);")
4344
.AddStatement("return deferred.promise;");
44-
45+
4546
return serviceBlock
4647
.Parent
4748
.Parent;
@@ -94,11 +95,11 @@ public void WriteServiceObjectToBlock(TypeScriptBlock serviceBlock, WebApiContro
9495
var endpointFullName = $"{Config.EndpointsNamespace}.{webApiController.Name}.{actionName}";
9596

9697
var cachedBlock = Config.EndpointsSupportCaching &&
97-
string.Equals(verb.Verb, "GET", StringComparison.InvariantCultureIgnoreCase)
98+
string.Equals(verb.Verb, WebApiHttpVerb.Get.Verb, StringComparison.InvariantCultureIgnoreCase)
9899
? new TypeScriptBlock()
99100
.AddAndUseBlock($"callCached<TView>({callArgumentDefinition})")
100101
.AddStatement($"return {Config.ServiceName}.callCached<TView>(this, {callArgumentValue});")
101-
: null;
102+
: null;
102103

103104
controllerBlock
104105
.AddAndUseBlock

src/WebApiToTypeScript/Endpoints/EndpointsService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ private void WriteInterfaceWithCallToBlock(TypeScriptBlock interfaceWithCallBloc
121121
interfaceWithCallBlock
122122
.AddStatement($"call<TView>({callArgumentsList}): ng.IPromise<TView>;");
123123

124-
if (Config.EndpointsSupportCaching && string.Equals(verb.Verb, "GET", StringComparison.InvariantCultureIgnoreCase))
124+
if (Config.EndpointsSupportCaching && string.Equals(verb.Verb, WebApiHttpVerb.Get.Verb, StringComparison.InvariantCultureIgnoreCase))
125125
interfaceWithCallBlock
126126
.AddStatement($"callCached<TView>({callArgumentsList}): ng.IPromise<TView>;");
127127
}

0 commit comments

Comments
 (0)