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

blackbird

v0.0.3

Published

Confortable interfacing of event based transports

Downloads

3

Readme

#Blackbird blackbird

Blackbird provides easy-to-use proxy objects that let you call methods across event based transports such as websockets, iframe postMessage channel etc. Instead of manually emitting and listening to events, blackbird lets you define interfaces that you can implement on one end point. On the other end point a proxy object is generated that you can call just as if it had been a local object. Any message based communication channel can be used so only your imagination sets the limit.

##Why? Without blackbird the code for requesting data from one endpoint to the other could look something like this:

// Endpoint A
var name;
window.addEventListener('message', function(e) {
  name = e.data;
  console.log(name);
});

window.postMessage('getName', '*');

// Endpoint B
window.addEventListener('message', function(e) {
  window.postMessage('Paul', '*');
});

This is not very generic and very error prone. Now compare it with the following blackbird code:

// Endpoint A
outbound.getName(function(err, name){
  console.log(name);
});

// Endpoint B
inbound.getName = function(){
  return Paul;
}

blackbird abstracts away the underlying messaging and lets you concentrate on your application logic instead. If you prefer promises over callback blackbird supports that too out of the box.

// Endpoint A
outbound.getName().then(function(name){
  console.log(name);
});

// Endpoint B
inbound.getName = function(){
  return Paul;
}

Blackbird can be used in node, in the browser per script tag and as an AMD module.

Follow @AronKornhall for news and updates regarding this library.

##Example (iframe postMessage) ###Embedding iframe The embedding iframe exposes a method getName

// Define a transport
var transport = blackbird.transports.iframe(window.parent);

// Inbound interface (will be called from remote)
var inbound = {
  getName: function(){
    return 'Paul';
  }
};

// Setup blackbird
blackbird(inbound, {}, transport);

###Embedded iframe The embedded iframe calls getName on embedding iframe

var iframe = document.getElementById('iframe');

// Define transport
var transport = blackbird.transports.iframe(iframe.contentWindow);

// Outbound interface (will be proxied to remote end)
var outbound = {
  getName: function(){ }
};

// Setup blackbird
blackbird({}, outbound, transport);

// Call getName on remote
outbound.getName(function(err, name){
  alert(name);
});

For a complete running example see examples/iframe/index.html

##Install Node

npm install blackbird

Browser

bower install blackbird
or download blackbird.js

##Test npm test

##Reference

blackbird(inbound, outbound, transport)

Setup blackbird with the inbound interface inbound, outbount interface outbound and transport transport.

Arguments

inbound   {Object} inbound interface containing method implementations that will
          be called by remote endpoint

outbound  {Object} outbound interface with functions that will be called on remote
          endpoint. The functions shouldn't be implemented, only defined

transport {Object} transport interface that should implement the following functions:
    send(data)
        data {String} the data to be sent to the remote endpoint
    listen(fn)
        fn {Function} registers fn as a listener for remote messages. fn accepts
                      a single {String} as input parameter

blackbird.transports.iframe(targetWindow, sourceWindow, domain)

Shorthand for creating an iframe transport from sourceWindow to targetWindow. domain is a domain mask that can be used to limit to which domains messages can be sent.

Arguments

targetWindow   {Object} the window to which we should send outgoing messages. To send messages to an embedded iframe use iframe.contentWindow (where iframe is the dom iframe element). To send data to the embedding (host) window of an embedded iframe as a target, use window.parent

sourceWindow   {Object} the window on which we should listen for incoming messages. Defaults to the global window.

domain  {String} the domain mask. Can be used to limit to which domains messages are sent. Defaults to '*' meaning any domain.

##License

(The MIT License)

Copyright (c) 2014 Aron Kornhall [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.