LogoLogo
HomepageResellerPricingSign in
  • AppMachine
  • πŸ“ƒProduct Updates
  • πŸ‘·Build your app
    • Preview your app
    • App templates
    • App Settings
    • Update payment method
    • Cancel subscription
  • ❔General App Building FAQ
  • How to
  • 🧱Blocks
    • πŸ” Admin
    • πŸ“„Blank Page
    • πŸ“žCall
    • 🏒Contact
    • πŸ“Contact Us
    • 🧾Coupons
    • πŸ“ƒCustom Form
    • πŸ“§Email
    • πŸ—“οΈEvents
    • ❔FAQ
    • 🌐Facebook
    • πŸ•‘Hours
    • ℹ️Information
    • πŸ“£Intro
    • β˜•JavaScript
    • πŸ”’Lock
    • 🎧Music
    • πŸ“°News
    • πŸ“ƒPDF
    • πŸ—ΊοΈPOI
    • πŸ‘₯People
    • πŸ“·Photos
    • 🏬Products
    • πŸ“©Push Messages
    • πŸ“»Radio
    • β†ͺ️Submenu
    • 🐦Twitter
    • πŸ‘¨β€πŸ’»URLs
    • πŸ–₯️Web Page
    • πŸ“ΊVideo
    • πŸ“±WhatsApp
  • πŸ“ƒData
    • Appmachine Data
    • Delete (test) data from Custom Form
    • Google Sheets
    • Web services
  • πŸ–ŒοΈStyle your app
    • Theme
    • Home Screen
    • FAQ Style
  • 🎨Style your screens
    • Elements
  • Share your app
    • ✈️Publishing your app
      • Technical Setup Quick Start Guide
      • Update your app
      • Unpublish an app from the app stores
    • 🌐Web App Publishing
      • Hosting on custom domain
    • 🍏Apple App Store
      • iOS developer account
      • App Store Connect API keys
      • Link your app
      • New app record in App Store Connect
      • App privacy details
      • Edit Store information
      • Fix App publish issues
      • Push certificates
      • App Store Connect app status overview
      • App Store Review Guidelines
      • Publish app Unlisted
      • Accept updated License agreement
      • Apple App Store FAQ
      • iPad
      • Enterprise
        • Setup your Enterprise app
        • Create iOS Distribution Certificate
        • Create App ID
        • Create Mobile Provisioning Profile
        • Downloading and installing an Enterprise app
    • 🍐Google Play
      • Create a Google Developer Account
      • Setup your Android app
      • How to request a Google Maps API Key
      • Test your Android app before publishing to Google Play
      • Upload your Android app to Google Play Store for the first time
      • Update Android app (short)
      • Update an Android app (extended)
      • Data safety details on the Google Play Store
      • Sell your app in Google Play Store
      • Create Google merchant account
      • Force Store Update for your Android App
      • Authorise an additional user to your Google Play developer account
      • What if my app is suspended by Google?
  • App details
    • πŸ•΅οΈGoogle Analytics
      • Google Analytics setup overview
      • Setup iOS analytics
      • Setup Android analytics
      • Inviting a new Google Analytics user
    • πŸ”₯Firebase
      • Create Firebase project
      • Locate Firebase Server key
      • Renew Firebase Server Key
      • Register iOS app
      • Register Android app
      • Enable Cloud Messaging
      • Enable Google Analytics
      • Google Analytics via Firebase
    • πŸ“¨Push notifications
      • Setup Apple Push certificate
    • πŸ§‘β€πŸ€β€πŸ§‘User management
      • Create Apple Sign In key
      • Setup Azure Active Directory
      • Create Facebook App ID Secret
    • 🐦Twitter API keys
    • πŸ”Privacy policy
    • πŸ‘©β€πŸ”§Your Account
      • Account Settings
      • Account FAQ
      • Payment FAQ
    • πŸ“±Admin CMS
  • Developers
    • πŸ‘©β€πŸ’»JavaScript
      • Develop locally
      • SDK
        • Core
        • JS Data
        • Media
        • Navigation
        • Notification
        • User
      • CLI
        • CLI Token and Secret
        • Errors
          • CONFIG_PROPERTIES_INVALID
          • CONFIG_VALUES_INVALID
          • ENTRY_FILE_NOT_FOUND
          • OUTPUT_DIRECTORY_IS_EMPTY
          • OUTPUT_DIRECTORY_NOT_FOUND
          • TOKEN_SECRET_NOT_PROVIDED
          • TOKEN_SECRET_NOT_VALID
      • Migrate from old Custom JS
    • πŸ’»Web services
Powered by GitBook
On this page
  • Get Block Name​
  • Get Property​
  • Get Image Url​
  • Show Loader​
  • Hide Loader​
  • Generic errors​

Was this helpful?

  1. Developers
  2. JavaScript
  3. SDK

Core

Core JavaScript features

PreviousSDKNextJS Data

Last updated 2 years ago

Was this helpful?

Integrate your JavaScript code with the basic functions of your AppMachine app. This page discusses the available functions and possible errors that lie at the basis of each JavaScript block.

Get Block Name

Get the current name of the block.

import { getBlockName } from '@myjsblock/sdk'

const myBlockName = await getBlockName();

// or

getBlockName().then(data => {  
    console.log(data);
});

Errors

Here is a list of errors that can be thrown when calling this function in addition to :

Error Code
Description

INVALID_ARGUMENT

The 'caption' property is not defined on the block.

Get Property

Get a property by name from the current block.

import { getProperty } from '@myjsblock/sdk'

const myProperty = await getProperty('myProperty');

// or

getProperty('myProperty').then(data => {  
    console.log(data);
});
Name
Type
Required
Default

propertyName

String

βœ…

-

Error Code
Description

INVALID_ARGUMENT

The provided propertyName is not found.

Get a public URL of an image, based on the given imageId.

import { getImageUrl } from '@myjsblock/sdk'

const myImage = await getImageUrl('myImageId');

const imageElement = document.createElement('img');
imageElement.src = myImage;

document.body.appendChild(imageElement);

By default the image URL that will be returned is the URL of the image in full resolution. We recommend using fixed dimensions for the width and height options when using high resolution images. This also improves performance and saves bandwidth.

import { getImageUrl } from '@myjsblock/sdk'

const myImage = await getImageUrl('myImageId', {    
    width: 300,    
    height: 300
});

const imageElement = document.createElement('img');
imageElement.src = myImage;

document.body.appendChild(imageElement);
import { getImageUrl } from '@myjsblock/sdk'

const myImageId = 'a181f12c-3116-11e5-80d0-00155d130a43';

const imageSourceDimensions = {    
    '300w': [280, 210],    
    '768w': [748, 561],    
    '1280w': [1260, 945]
};

const imageSourcePromises = Object.values(imageSourceMap).map(([width, height]) => getImageUrl('myImageId', { width, height }));

const imageSourceUrls = await Promise.all(imageSourcePromises);

const imageSourceMap = Object.entries(imageSourceDimensions).map(([viewPortWidth], dimensionIndex) => [viewPortWidth, imageSourceUrls[dimensionIndex]]);
// Returns array of e.g. ['300w', 'https://myasseturl...']

const sourceSet = imageSourceMap.map(([viewPortWidth, imageUrl]) => `${imageUrl} ${viewPortWidth}`).join(', ');

const imageElement = document.createElement('img');

const defaultImage = imageSourceMap[0][1]; // Smallest image
imageElement.src = defaultImage;

imageElement.srcset = sourceSet;

document.body.appendChild(imageElement);
<html>    
    <body>
        <img            
            src="https://static.accept.appmachine.com/api/image/x/a181f12c-3116-11e5-80d0-00155d130a43"            
            srcset="https://static.accept.appmachine.com/api/image/280x210/a181f12c-3116-11e5-80d0-00155d130a43 300w, https://static.accept.appmachine.com/api/image/748x561/a181f12c-3116-11e5-80d0-00155d130a43 768w, https://static.accept.appmachine.com/api/image/1260x945/a181f12c-3116-11e5-80d0-00155d130a43 1280w"        
        />    
    </body>
</html>
Name
Type
Required
Default

imageId

String

βœ…

-

dimensions

{ width: Number, height: Number }

-

Error Code
Description

INVALID_ARGUMENT

imageId is missing or the width or height isn't a number.

Show an overlay with a spinner.

import { showLoader, hideLoader } from '@myjsblock/sdk'const loadData = async () => {  await showLoader()  try {    await fetchData()  } finally {    await hideLoader()  }}

Hide the loader overlay that was shown by the showLoader function.

import { showLoader, hideLoader } from '@myjsblock/sdk'const loadData = async () => {  await showLoader()  try {    await fetchData()  } finally {    await hideLoader()  }}
Error Code
Description

OPERATION_NOT_ALLOWED

There is no active loader.

Error Code
Description

UNKNOWN_ERROR

Unknown error occurred.

TIMEOUT_EXCEEDED

The app failed to respond within the set timeout.

UNKNOWN_FUNCTION

The function that was called doesn't exist.

VERSION_NOT_SUPPORTED

The function isn't supported in the current version of the app.

Arguments

Errors

Here is a list of errors that can be thrown when calling this function in addition to :

Get Image Url

Image Resizing

Basic Example

Multiple Image sizes

It is also possible to use multiple image resolution depending on the device resolution or pixel density using image src sets. Read for more information.

Result

Arguments

Errors

Here is a list of errors that can be thrown when calling this function in addition to :

Show Loader

Hide Loader

Errors

Here is a list of errors that can be thrown when calling this function in addition to :

Generic errors

πŸ‘©β€πŸ’»
​
​
generic errors
​
​
​
generic errors
​
​
​
​
MDN guide
​
​
​
generic errors
​
​
​
generic errors
​