-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
21 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Constants | ||
|
||
Constants are the simplest structure that we find inside the `TypedApi`. Constants are hard-coded key-value pairs that are embedded in the runtime metadata. In PAPI their structure is just a simple function that return its decoded value, with two alternatives. As explained in [the previous section](/typed) for `isCompatible`, we have two options to get the value: | ||
|
||
- Promise-based call, without passing the runtime | ||
- Synchronous return, passing the runtime previously awaited for | ||
|
||
Let's use `typedApi.constants.System.Version`. See in this example how it's used: | ||
|
||
```ts | ||
// in this case the function is asynchronous | ||
const versionAsync = await typedApi.constants.System.Version() | ||
|
||
const runtime = await typedApi.runtime.latest() // we already learnt about it! | ||
// in this case it's sync | ||
const versionSync = typedApi.constants.System.Version(runtime) | ||
``` |
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