stackqueue

1.0.2 • Public • Published

Stack

This stack queue replicates async function like the one used in the Google Analytics (GA) snippet.

Where this comes in handy is putting javascript snippets on html pages without requiring external scripts. The ability to push data and events into a queue before a larger javascript file is loaded is invaluable in certain circumstances.

The code required to set up a stack queue object that is compatible with this library is minimal.

Browser

Usage like newer Google Analytics, wrapped in a function.

// Setup
var arr = [];
sq = sq || function() {
  arr.push(arguments);
};
sq.arr = sq.arr || arr;

// Usage
sq("log", "hello from stack!");

App

From our app we can treat the stack queue object as if it were created by the library.

var stackqueue = require("stackqueue");

var log = function(message) {
  console.log(message);
};

// Here we grab the sq declared in our html and initialise it.
stackqueue.flush(window.sq, { log: log });

// Output: "hello from stack!"

Readme

Keywords

Package Sidebar

Install

npm i stackqueue

Weekly Downloads

0

Version

1.0.2

License

MIT

Last publish

Collaborators

  • tbillington