Skip to content

Commit 7c8a230

Browse files
committed
Fix an error with wrong key.
Simplify storing cached data.
1 parent 5b887ca commit 7c8a230

File tree

3 files changed

+8
-16
lines changed

3 files changed

+8
-16
lines changed

src/WebApiTestApplication/Scripts/Endpoints/Service.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,15 @@ namespace Endpoints {
2121
}
2222

2323
static callCached<TView>(endpoint: IEndpoint, data) {
24-
if (this.endpointCache[endpoint._verb] == null) {
25-
this.endpointCache[endpoint._verb] = {};
26-
}
27-
28-
if (this.endpointCache[endpoint._verb][data] == null) {
24+
if (this.endpointCache[endpoint.toString()] == null) {
2925
return this.call(endpoint, data).then(result => {
30-
this.endpointCache[endpoint._verb][data] = result;
31-
return this.endpointCache[endpoint._verb][data];
26+
this.endpointCache[endpoint.toString()] = result;
27+
return this.endpointCache[endpoint.toString()];
3228
});
3329
}
3430

3531
const deferred = this.$q.defer();
36-
deferred.resolve(this.endpointCache[endpoint._verb][data]);
32+
deferred.resolve(this.endpointCache[endpoint.toString()]);
3733
return deferred.promise;
3834
}
3935

src/WebApiToTypeScript/Config/Config.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Collections.Generic;
2-
using System.Diagnostics.Eventing.Reader;
32

43
namespace WebApiToTypeScript.Config
54
{

src/WebApiToTypeScript/Endpoints/AngularEndpointsService.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,15 @@ public TypeScriptBlock CreateServiceBlock()
3131
serviceBlock
3232
.Parent
3333
.AddAndUseBlock("static callCached<TView>(endpoint: IEndpoint, data)")
34-
.AddAndUseBlock($"if (this.endpointCache[endpoint._verb] == null)")
35-
.AddStatement("this.endpointCache[endpoint._verb] = {};")
36-
.Parent
37-
.AddAndUseBlock("if (this.endpointCache[endpoint._verb][data] == null)")
34+
.AddAndUseBlock("if (this.endpointCache[endpoint.toString()] == null)")
3835
.AddAndUseBlock("return this.call(endpoint, data).then(result =>", isFunctionBlock: true,
3936
terminationString: ";")
40-
.AddStatement("this.endpointCache[endpoint._verb][data] = result;")
41-
.AddStatement("return this.endpointCache[endpoint._verb][data];")
37+
.AddStatement("this.endpointCache[endpoint.toString()] = result;")
38+
.AddStatement("return this.endpointCache[endpoint.toString()];")
4239
.Parent
4340
.Parent
4441
.AddStatement("const deferred = this.$q.defer();")
45-
.AddStatement("deferred.resolve(this.endpointCache[endpoint._verb][data]);")
42+
.AddStatement("deferred.resolve(this.endpointCache[endpoint.toString()]);")
4643
.AddStatement("return deferred.promise;");
4744

4845
return serviceBlock

0 commit comments

Comments
 (0)