New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

applyq

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

applyq

A JavaScript library for applying asynchronous calls to an API.

  • 0.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
86
decreased by-58.85%
Maintainers
1
Weekly downloads
 
Created
Source

applyq

A JavaScript library for applying asynchronous calls to an API.

Dependency Status Build Status npm version

Installation

npm install --save applyq

How the Asynchronous Syntax Works

Lets say there is a JavaScript object on the page but it is unknown where and when it will be loaded. However, you would like to have the possibility to interact with it at any place on the page. The asynchronous syntax makes it possible to call the API before its loaded.

The asynchronous syntax uses a queue, which is a first-in, first-out data structure that collects API calls until the target object is ready to execute them.

To push an API call onto the queue, you must convert it from the traditional JavaScript syntax into a command array. Command arrays are simply JavaScript arrays that conform to a certain format. The first element in a command array is the name of the object method you want to call. It must be a string. The rest of the elements are the arguments you want to pass to the object method. These can be any JavaScript value.

The following code calls logger.log using the traditional syntax:

logger.log('Hello world!');

The equivalent code in the asynchronous syntax:

window._loggerq = window._loggerq || [];
_loggerq.push(['log', 'Hello world!']);

Usage

Once the object is loaded and initialized, it has to execute the queued command arrays. This can be done by calling applyq:

var logger = new Logger();
applyq(logger, _loggerq);

After the object had been initialized, there is no need to store the commands anymore. The commands can be executed right away. That's why after calling applyq the push method of the commands queue is overridden. The overridden version of push is executing the command arrays immediately instead of storing them.

Whitelist of methods

You might want to process a subset of commands only. In that case you can path the list of commands to process:

/* In this case only commands passed to the register() method will be processed */
applyq(server, _serverq, ['register']);

P.S.

Some of the explanations of the Asynchronous Syntax were taken from Google Analytics Tracking Basics (Asynchronous Syntax).

License

MIT

FAQs

Package last updated on 26 Nov 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc