npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tag-queue

v1.1.4

Published

Organise scripts startup when dealing with tag manager

Downloads

3

Readme

tag-queue

This small library aims to organise your scripts using very simplified deferred pattern.

Currenly lib weight only 1.6K (857B gzipped).

Table of contents

Namespace Deprecation

In previous versions we maintained window.tq as default handle for library. At the moment it will work only, if other script haven't defined it already.

Library will be loaded to window as window.tagQueue. I googled for it and no one seems to use it (except window.TagQueue, so thanks for case sensitivity in JavaScript).

Installation

NPM

npm install tag-queue

Bower

bower install tag-queue

Custom

You can directly load one of files from dist folder:

  • /dist/index.js
  • /dist/index.js.gz

Tealium

You can put /dist/index.js verison into Custom Tealium Container

API

tagQueue(dependencies, callback, useTimer)

Queues callback for given dependencies. It will execute it immediately, if dependencies are already met.

  • dependencies
    • String as URL - string starting with http:// or https:// will inject observed loader script
    • String - name of dependency, have to be reported manually using tagQueue.got
    • Array - array of mixed dependencies, when all are met callback is fired
  • callback
    • Function - function(tq)
      • Function tq - reference to window.tagQueue
  • useTimer
    • Boolean - if true will observe window[dependency] and will fire tagQueue.got once field is defined. Can't be used for dependencies as array.
    • default false

tagQueue.t(dependency)

Tells queue to observe specific dependency on window (window[dependency]). It's usefull when you declare combined dependencies and one of them require window observing.

  • dependency
    • String - name of dependency. URL and Array are not supported here

tagQueue.got(dependency)

Reports specific dependency is met

  • dependency
    • String as URL - URL of dependency from loader
    • String - name of dependency

tagQueue.process(array, wrapper)

Iterates on array expecting customQueue callbacks or customQueue complex callbacks. Translate them to calls on tagQueue.

  • array
    • Array of customQueue callbacks or customQueue complex callbacks
  • wrapper
    • Function will be used to wrap callbacks
    • undefined by default

Wrapper is used to handle errors in callbacks. It can be used by you to add extra error reporting or insights to specific callbacks. We inject to each wrapper instance of currently processed callback. Default callback replicate behaviour of tagQueue so injects instance of it.

Default wrapper:

function(callback) {
  try {
    callback(tq);
  } catch(ex) {
    // unheld exception
  }
}

customQueue callback

Function will be exectured immediately - the same as in tagQueue

customQueue complex callback

Array representing followign arguments of tagQueue:

  • String or Array for dependencies
  • Function for callback
  • Boolean for useTimer

Use cases

Simple promise

/**
 * Register load listener
 */ 
tq('myLib', function() {
	(…)
});

/**
 * Inform that lib has been loaded
 */
tq.got('myLib');

Observable script loader

/**
 * NOW! You can also load some libs with crossbrowser callback. Simply use http:// https:// or ://
 */
tq('https://connect.facebook.net/en_US/sdk.js', function() {
  console.log('got Facebook SDK');
});

Window observing

/**
 * Adding true as second parameter makes lib observe window[<LIB_NAME>] and trigger callback once loaded.
 */
tq('jquery', function() {
   console.log('got jQuery');
}, true);

Combined dependencies

/**
 * You can also require comined dependencies
 */ 
tq(['jquery', 'myLib'], function(){
	(...)
});

/**
 * And tell that we need to observe one specific lib
 */
tq.t('jquery');

/**
 * As it's deferred you can also attach listeners after load event was triggered
 */
tq('myLib', function() {
	// will work even after lq.got('myLib') was fired
});

Pre-load queueing


var myQueue = myQueue || [];

myQueue.push(function(){
	// my calback
	console.log('A');
});

myQueue.push(['next',function(){
	// got 'next'
	console.log('B');
]);

myQueue.push(['jquery',function(t){
	// i have jQuery
	t.got('next'); // so I can say I am ready
	console.log('C');
}
],true);

…

tagQueue.process(myQueue);

will result as

A
C
B

Credits

Idea and requirements thanks to Tomasz Witkowski.

Code version 0.0.1 Łukasz Marek Sielski.