Skip to content

Commit f0a5fd8

Browse files
backwards compatibility
Signed-off-by: Xavier Geerinck <xavier.geerinck@gmail.com>
1 parent 147894c commit f0a5fd8

File tree

2 files changed

+50
-7
lines changed

2 files changed

+50
-7
lines changed

src/actors/client/ActorProxyBuilder.ts

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,57 @@ export default class ActorProxyBuilder<T> {
2222
actorClient: ActorClient;
2323
actorAbstractClass: Class<T>;
2424

25-
constructor(actorTypeName: string, actorTypeClass: Class<T>, daprClient: DaprClient);
25+
constructor(actorTypeClass: Class<T>, daprClient: DaprClient);
26+
constructor(
27+
actorTypeClass: Class<T>,
28+
host: string,
29+
port: string,
30+
communicationProtocol: CommunicationProtocolEnum,
31+
clientOptions: DaprClientOptions,
32+
);
2633
constructor(
2734
actorTypeName: string,
28-
abstractClass: Class<T>,
35+
actorTypeClass: Class<T>,
36+
daprClient: DaprClient
37+
);
38+
constructor(
39+
actorTypeName: string,
40+
actorTypeClass: Class<T>,
2941
host: string,
3042
port: string,
3143
communicationProtocol: CommunicationProtocolEnum,
3244
clientOptions: DaprClientOptions,
3345
);
34-
constructor(actorTypeName: string, abstractClass: Class<T>, ...args: any[]) {
46+
constructor(...args: any[]) {
47+
let actorTypeName: string;
48+
let actorTypeClass: Class<T>;
49+
let rest: any[];
50+
51+
// Determine if the first argument is a string (actorTypeName) or a class
52+
if (typeof args[0] === "string") {
53+
actorTypeName = args[0];
54+
actorTypeClass = args[1];
55+
rest = args.slice(2);
56+
} else {
57+
actorTypeClass = args[0];
58+
actorTypeName = actorTypeClass.name;
59+
rest = args.slice(1);
60+
}
61+
3562
this.actorTypeName = actorTypeName;
36-
this.actorAbstractClass = abstractClass;
63+
this.actorAbstractClass = actorTypeClass;
3764

3865
// Create the actor client based on the provided arguments
39-
if (args.length == 1) {
40-
const [daprClient] = args;
66+
if (rest.length == 1) {
67+
const [daprClient] = rest;
4168
this.actorClient = new ActorClient(
4269
daprClient.options.daprHost,
4370
daprClient.options.daprPort,
4471
daprClient.options.communicationProtocol,
4572
daprClient.options,
4673
);
4774
} else {
48-
const [host, port, communicationProtocol, clientOptions] = args;
75+
const [host, port, communicationProtocol, clientOptions] = rest;
4976
this.actorClient = new ActorClient(host, port, communicationProtocol, clientOptions);
5077
}
5178
}

test/e2e/http/actors.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,22 @@ describe("http/actors", () => {
161161
expect(c3).toEqual(11);
162162
});
163163

164+
it("should be able to create an actor object through the proxy and the deprecated way of working (when we have the implementation)", async () => {
165+
const builder = new ActorProxyBuilder<DemoActorCounterInterface>(DemoActorCounterImpl, client);
166+
const actor = builder.build(ActorId.createRandomId());
167+
168+
const c1 = await actor.getCounter();
169+
expect(c1).toEqual(0);
170+
171+
await actor.countBy(1, 1);
172+
const c2 = await actor.getCounter();
173+
expect(c2).toEqual(1);
174+
175+
await actor.countBy(1, 10);
176+
const c3 = await actor.getCounter();
177+
expect(c3).toEqual(11);
178+
});
179+
164180
it("should be able to create an actor object through the proxy (without requiring the implementation)", async () => {
165181
const builder = new ActorProxyBuilder<DemoActorCounterContract>("DemoActorCounterImpl", DemoActorCounterContract, client);
166182
const actor = builder.build(ActorId.createRandomId());

0 commit comments

Comments
 (0)