-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix import statements and update dependencies
- Loading branch information
RSamaium
committed
Dec 2, 2023
1 parent
658f971
commit db0a87f
Showing
7 changed files
with
67 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Using `inject` in RPGJS | ||
|
||
The `inject` function in RPGJS is a powerful feature for dependency injection, allowing you to retrieve instances of various classes in both client and server environments. | ||
|
||
## Client-Side Injection | ||
|
||
To use `inject` on the client side, import it from `@rpgjs/client`. This allows you to retrieve singleton instances of classes such as `RpgClientEngine`, `KeyboardControls`, and `RpgRenderer`. | ||
|
||
### Retrieving the `RpgClientEngine` | ||
|
||
```typescript | ||
import { inject, RpgClientEngine } from '@rpgjs/client' | ||
|
||
const client = inject(RpgClientEngine) | ||
``` | ||
|
||
This code imports `inject` and `RpgClientEngine` from `@rpgjs/client` and then uses `inject` to retrieve the `RpgClientEngine` instance. | ||
|
||
### Injecting Other Classes | ||
|
||
Similarly, you can inject other classes like `KeyboardControls` and `RpgRenderer`: | ||
|
||
```typescript | ||
import { inject, KeyboardControls, RpgRenderer } from '@rpgjs/client' | ||
|
||
const controls = inject(KeyboardControls) | ||
const renderer = inject(RpgRenderer) | ||
``` | ||
|
||
## Server-Side Injection | ||
|
||
For server-side injection, import `inject` from `@rpgjs/server`. This is typically used to retrieve the `RpgServerEngine`. | ||
|
||
### Retrieving the `RpgServerEngine` | ||
|
||
```typescript | ||
import { inject, RpgServerEngine } from '@rpgjs/server' | ||
|
||
const server = inject(RpgServerEngine) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters