Skip to content

Commit

Permalink
feat: add constants
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosala committed May 15, 2024
1 parent fcad2ba commit e595b0c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions docs/pages/typed/constants.md
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)
```
4 changes: 4 additions & 0 deletions vocs.config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export default defineConfig({
text: "Typed API",
link: "/typed",
items: [
{
text: "Constants",
link: "/typed/constants",
},
{
text: "Storage queries",
link: "/typed/queries",
Expand Down

0 comments on commit e595b0c

Please sign in to comment.