SDK
@myjsblock/sdk
A guide to start with the MyJSBlock SDK. For a quick introduction we suggest reading our introduction.
Setup your project (e.g. with Vite)β
We recommend using a build tool like Vite, it is an easy to use development tool for all kinds of frameworks. It also has support for creating PWAs and more. It is not required, you can also use your own setup.
With npm:
npm create vite
With yarn:
yarn create vite
After a couple of questions Vite will create a starter project for you. If you just want use regular JavaScript you can choose 'vanilla'.
Installationβ
NPMβ
npm install @myjsblock/sdk
Yarnβ
yarn add @myjsblock/sdk
Before we beginβ
All the modules the SDK exposes are functions, every function in the SDK returns a promise. If you're not familiar with Javascript Promises checkout this page on MDN.
Your first functionβ
In JavaScript you're able to call functions that will interact with your AppMachine App. Simply import the function and call it.
Exampleβ
HTML
<body>
<button id="loader-button">
Show Loader
</button>
</body>
JavaScript
import { showLoader, hideLoader } from '@myjsblock/sdk'
const loadingButton = document.getElementById('loader-button');
loadingButton.addEventListener('click', async () => {
await showLoader();
await new Promise((resolve) => { setTimeout(resolve, 2000) });
await hideLoader();
});
See this example on GitHub.
Publish it with the CLIβ
If you haven't installed the CLI yet, follow the steps in our Getting Started.
Link your project to a blockβ
myjsblock link
Push your projectβ
myjsblock link
Last updated
Was this helpful?