Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gazette

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gazette - npm Package Compare versions

Comparing version 0.9.0 to 0.9.1

tests/test.js

82

ender.js

@@ -5,58 +5,58 @@ // Gazette Ender

(function ($) {
// s for "subscription""
var cache = $.pubsub_cache = {};
// s for "subscription""
var cache = $.pubsub_cache = {};
function publish (topic, args) {
function publish (topic, args) {
// Bulletproof args so that we always have an array
args = ($.isArray(args)) ? args : [args];
// Do we have a subscription?
if (cache) {
// yes : start firing off the events with the localized scole
for (var t = 0, len = cache.length; t < len; t++) {
cache[t].apply(cache[t].scope, args || []);
}
}
}
// Bulletproof args so that we always have an array
args = ($.isArray(args)) ? args : [args];
// Do we have a subscription?
if (cache) {
// yes : start firing off the events with the localized scole
for (var t = 0, len = cache.length; t < len; t++) {
cache[t].apply(cache[t].scope, args || []);
}
}
}
function subscribe (topic, callback){
function subscribe (topic, callback){
if(!cache[topic]){
cache[topic] = [];
}
if(!cache[topic]){
cache[topic] = [];
}
// Add an attribute of the function to localize "this"
callback.scope = this;
// Add an attribute of the function to localize "this"
callback.scope = this;
cache[topic].push(callback);
cache[topic].push(callback);
return [topic, callback ];
return [topic, callback ];
}
}
function unsubscribe (handle){
function unsubscribe (handle){
var t = handle[0];
var t = handle[0];
if (cache[t]) {
if (cache[t]) {
for (var u = 0, len = cache[t].length; u < len; u++) {
if(cache[t][u] === handle[1]){
cache[t].splice(u, 1);
}
}
for (var u = 0, len = cache[t].length; u < len; u++) {
if(cache[t][u] === handle[1]){
cache[t].splice(u, 1);
}
}
}
}
}
}
// Now let's hook things up
$.publish = publish;
$.subscribe = subscribe;
$.unsubscribe = unsubscribe;
// Now let's hook things up
$.publish = publish;
$.subscribe = subscribe;
$.unsubscribe = unsubscribe;
$.ender({ subscribe: subscribe, unsubscribe: unsubscribe }, true);
$.ender({ subscribe: subscribe, unsubscribe: unsubscribe }, true);
}(ender));
}(ender));

@@ -5,52 +5,58 @@ // Gazette

module.exports = function (context) {
function Gazette (context) {
var cache = context.pubsub_cache = {};
context = context || {};
context.pubsub_cache = context.pubsub_cache || {};
function publish (topic, args){
context.publish = function (topic, args){
var cache = context.pubsub_cache;
var target = cache[topic];
args = ($.isArray(args)) ? args : [args];
if (target) {
for (var t = 0, len = target.length; t < len; t++) {
target[t].apply(context, args || []);
};
args = (toString.call(args) === "[object Array]") ? args : [args];
// Do we have a subscription?
if (cache[topic]) {
// yes : start firing off the events with the localized scole
for (var t = 0, len = cache[topic].length; t < len; t++) {
cache[topic][t].apply(context, args);
}
}
};
function subscribe (topic, callback){
context.subscribe = function (topic, callback){
var cache = context.pubsub_cache;
if(!cache[topic]){
cache[topic] = [];
}
cache[topic] = [];
}
cache[topic].push(callback);
cache[topic].push(callback);
return [topic, callback];
return [topic, callback];
};
function unsubscribe (handle){
context.unsubscribe = function (handle){
var t = handle[0];
var t = handle[0]
, cache = context.pubsub_cache;
if (cache[t]) {
if (cache[t]) {
for (var u = 0, len = cache[t].length; u < len; u++) {
if(cache[t][u] == handle[1]){
cache[t].splice(u, 1);
}
}
if(cache[t][u] === handle[1]){
cache[t].splice(u, 1);
}
}
}
};
context['publish'] = publish;
context['subscribe'] = subscribe;
context['unsubscribe'] = unsubscribe;
};
return context;
};
module.exports = new Gazette();
// Infuse any object with pubsub
module.exports.infuse = Gazette;
{
"name" : "gazette",
"description" : "A very simple module for pubsub. Ender compliant.",
"description" : "Add pubsub to anything. Ender compliant.",
"author" : "Nate Hunzaker <nate.hunzaker@gmail.com> (natehunzaker.com)",
"version" : "0.9.0",
"version" : "0.9.1",

@@ -8,0 +8,0 @@ "main" : "./gazette.js",

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