* Use `eq` for example * Use the base `eq` function rather than `===`, so that comparisons are made in a consistent manner in docs * Add `eq` example * Add an example of using the `eq` method to the base docs * Adjust docs/examples * Fix a number of typos in the static docs and examples * Adjust various comments in docs examples such that they are written in a consistent case * Fix metadata docs spacing * Adjust the metadata documentation generation such that unnecessary spaces are trimmed
29 lines
865 B
JavaScript
29 lines
865 B
JavaScript
/* eslint-disable @typescript-eslint/require-await */
|
|
/* eslint-disable @typescript-eslint/unbound-method */
|
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
// Import the API
|
|
const { ApiRx } = require('@polkadot/api');
|
|
const { switchMap } = require('rxjs/operators');
|
|
|
|
async function main () {
|
|
// Create a new instance of the api
|
|
// Subscribe to chain updates and log the current block number on update.
|
|
const subscription = new ApiRx().isReady
|
|
.pipe(
|
|
switchMap((api) =>
|
|
api.rpc.chain.subscribeNewHead()
|
|
))
|
|
.subscribe((header) => {
|
|
console.log(`Chain is at block: #${header.number}`);
|
|
});
|
|
|
|
// In this example we're calling the Overvables unsubscribe() //
|
|
// function after 20s.
|
|
setTimeout(() => {
|
|
subscription.unsubscribe();
|
|
console.log('Unsubscribed');
|
|
}, 20000);
|
|
}
|
|
|
|
main().catch(console.error);
|