You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: daprdocs/content/en/js-sdk-docs/js-actors/_index.md
+92-98Lines changed: 92 additions & 98 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,116 +6,132 @@ weight: 1000
6
6
description: How to get up and running with Actors using the Dapr JavaScript SDK
7
7
---
8
8
9
-
The Dapr actors package allows you to interact with Dapr virtual actors from a JavaScript application. The below examples demonstarte how to use the JavaScript SDK for interacting with virtual actors.
9
+
The Dapr actors package allows you to interact with Dapr virtual actors from a JavaScript application. The examples below demonstrate how to use the JavaScript SDK for interacting with virtual actors.
10
10
11
-
For a more in-depth overview of Dapr actors and supported scenarios, visit the [actors overview page]({{< ref actors-overview >}}).
11
+
For a more in-depth overview of Dapr actors, visit the [actors overview page]({{< ref actors-overview >}}).
The below code examples loosely describe the scenario of a Parking Garage Spot Monitoring System, which can be seen in this [video] by Mark Russinovich(https://www.youtube.com/watch?v=eJCu6a-x9uo&t=3785).
21
+
22
+
A parking garage consists of hundreds of parking spaces, where each parking space includes a sensor that provides updates to a centralized monitoring system. The parking space sensors (our actors) detect if a parking space is occupied, or available.
23
+
24
+
To jump in and run this example yourself, clone the source code, which can be found in the [JavaScript SDK examples directory](https://github.com/dapr/js-sdk/tree/master/examples/http/actor-parking-sensor).
25
+
19
26
## Actor Interface
20
-
The actor interface defines the contract that is shared between the actor implementation and the clients calling the actor.
27
+
The actor interface defines the contract that is shared between the actor implementation and the clients calling the actor. In the example below, we have created an interace for a parking garage sensor. Each sensor has 2 methods: `carEnter` and `carLeave`, which defines the state of the parking space:
21
28
22
29
```javascript
23
-
exportdefaultinterface ActorSayInterface {
24
-
say(msg: string): string;
30
+
exportdefaultinterface ParkingSensorInterface {
31
+
carEnter():Promise<void>;
32
+
carLeave():Promise<void>;
25
33
}
26
34
```
27
35
28
36
## Actor Implementation
29
-
An actor implementation defines a class by extending the base type `AbstractActor` and implements the interfaces defined in the actor interface.
37
+
An actor implementation defines a class by extending the base type `AbstractActor` and implements the actor interface. The following code describes what an actor implmentation consists of by implementing the methods defined in the `ParkingSensorInterface`. It also defines a few extra helper methods:
// Implementation that updates state that this parking spaces is occupied.
46
+
}
47
+
48
+
asynccarLeave():Promise<void> {
49
+
// Implementation that updates state that this parking spaces is available.
50
+
}
51
+
52
+
asyncgetParkingSpaceUpdate():Promise<object> {
53
+
// Implementation of requesting an update from the parking space sensor.
54
+
}
55
+
56
+
asynconActivate():Promise<void> {
57
+
// Initialization logic called by AbstractActor.
58
+
}
39
59
}
40
60
```
41
61
42
-
## Invoking Actors
43
-
Use the DaprServer package to create your actors bindings, which will initalize and register your actors. After Actors are registered, use the DaprClient to invoke methods on an actor. The will client call the actor methods defined in the actor interface.
62
+
## Registering Actors
63
+
Initialize and register your actors by using the DaprServer package:
0 commit comments