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

wen

v1.1.0

Published

Triggers events based on the truthiness of predicate methods

Downloads

66

Readme

wen

You're waiting for some arbitrary thing to load in your browser, or for something to happen, but that thing doesn't have an evented interface. What a pain in the butt.

wen to the rescue!

Usage

var wen = require('wen');
var truth = wen();
var somePredicate; // Currently falsy

truth.on('the-thing-happened', function () {
	console.log('React to the thing that happened here!');
});

truth.add(function () {
	// At some point, some external force made somePredicate truthy
	return somePredicate;
}, 'the-thing-happened');

Install

NodeJS, Browserify, etc. (CommonJS)

npm install wen --save

Good ol' fashioned Browser

Copy this into your HTML somewhere.

<script src="https://raw.githubusercontent.com/basicallydan/wen/master/dist/wen.1.0.1.min.js"></script>
<!-- If I want to do this properly I will download it and place it in my source code somewhere -->

Simple.

How does it work?

Easy: you give it a predicate and some event name (whatever you want!), it checks every 1000ms (or less, or more, if you specify) if that predicate is truthy. When it finally is truthy, it'll trigger that event name. It extends an Event Emitter, so in fact it will also have all of the methods of the event emitter, such as .once and .trigger.

Dependencies

There are only two direct dependencies. For the compiled .min.js version they are bundled so don't worry about it. They are:

  • Wolfy87's Event Emitter, a lightweight event emitter which works well in browsers as well as in NodeJS.
    • ✓ Has no dependencies.
  • vmattos's JS Extend, inspired by the Underscore _.extend method.
    • ✓ Also has no dependencies.

This makes for a total of two dependencies. You could probably read the entire source in about half an hour. I dare you.

Changes

  • 1.0.1: I forgot to make it browser friendly and didn't account for a dev error which I should've done. Now I have.
  • 1.0.0: First.

"FAQ"

I cloned your repo what are those makefile files for?

Contributors who want to bundle the JS into the minified form (for the spec, too). Don't touch 'em unless you know what you're doing!

Can I contribute?

Sure you can! If you have a suggestion, make an issue. If you've fixed something, open a pull request. This is a very simple module.

Who made this, and when?!

Dan Hough (@basicallydan on Twitter and everywhere) did, while he was working as a contractor for upmysport.