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

mediator-js

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mediator-js - npm Package Compare versions

Comparing version 0.9.4 to 0.9.5

24

lib/mediator.js

@@ -16,17 +16,17 @@ /*jslint bitwise: true, nomen: true, plusplus: true, white: true */

(function(root, factory) {
(function(global, factory) {
'use strict';
if(typeof root.exports === 'function') {
if(typeof exports !== 'undefined') {
// Node/CommonJS
root.exports.Mediator = factory();
exports.Mediator = factory();
} else if(typeof define === 'function' && define.amd) {
// AMD
define('mediator-js', [], function() {
root.Mediator = factory();
return root.Mediator();
global.Mediator = factory();
return global.Mediator();
});
} else {
// Browser global
root.Mediator = factory();
global.Mediator = factory();
}

@@ -203,3 +203,4 @@ }(this, function() {

called = false,
subscriber, l;
subscriber, l,
subsBefore,subsAfter;

@@ -216,3 +217,9 @@ // Priority is preserved in the _subscribers index.

}else{
subsBefore = this._subscribers.length;
subscriber.fn.apply(subscriber.context, data);
subsAfter = this._subscribers.length;
y = subsAfter;
if (subsAfter === subsBefore - 1){
x--;
}
called = true;

@@ -229,4 +236,2 @@ }

x--;
}else{
subscriber.update(subscriber.options);
}

@@ -356,1 +361,2 @@ }

}));
MIT License Terms
=================
Copyright (c) 2013 Jack Lawson, LLC.
Copyright (c) 2013 Jack Lawson

@@ -6,0 +6,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of

{
"name": "mediator-js",
"version": "0.9.4",
"version": "0.9.5",
"description": "Flexible event management. Implementation of the mediator pattern.",

@@ -5,0 +5,0 @@ "author": "Jack Lawson <jlawson@olivinelabs.com>",

@@ -5,16 +5,10 @@ Mediator.js

Version 0.9.4
Version 0.9.5
For more information, please see
* [View the documentation](http://thejacklawson.com/Mediator.js/)
* [View the project on Github](https://github.com/ajacksified/Mediator.js)
* [Relevant blog post](http://thejacklawson.com/2011/06/mediators-for-modularized-asynchronous-programming-in-javascript/)
* Documentation built using [Paige](https://github.com/rthauby/Paige)
* [Changelog](#changelog)
[Relevant blog post](http://thejacklawson.com/2011/06/mediators-for-modularized-asynchronous-programming-in-javascript/)
[View the project on Github](https://github.com/ajacksified/Mediator.js)
[View the documentation](http://thejacklawson.com/Mediator.js/)
Documentation built using [Paige](https://github.com/rthauby/Paige)
[Changelog][]
A light utility class to help implement the Mediator pattern for easy eventing

@@ -215,2 +209,5 @@ ------------------------------------------------------------------------------

__Version 0.9.5__
* Fixed issue with requring from node
__Version 0.9.4__

@@ -217,0 +214,0 @@ * Fixed issue with auto-removing subscribers after a maximum amount of calls

@@ -200,3 +200,3 @@ var Mediator = require("../index").Mediator,

it("should do nothing if an valid fn is given", function(){
it("should do nothing if an invalid fn is given", function(){
var spy = sinon.spy(),

@@ -272,3 +272,34 @@ invalidFn = "derp";

});
it("should call all matching subscribers with context", function(){
var spy = sinon.spy(),
data = ["data"];
channel.addSubscriber(function() { this(); }, {}, spy );
channel.publish(data);
expect(spy).called;
});
it("should call subscribers in predefined priority", function(){
var sub1 = function(){
this.a += "1";
},
sub2 = function(){
this.a += "2";
},
sub3 = function(){
this.a += "3";
},
data = ["data"];
this.a = "0";
channel.addSubscriber(sub3, {}, this);
channel.addSubscriber(sub1, { priority: 2 }, this);
channel.addSubscriber(sub2, { priority: 1 }, this);
channel.publish(data);
expect(this.a).to.equal("0123");
});
});
});

@@ -167,3 +167,50 @@ var Mediator = require("../index").Mediator,

expect(spy2).called;
});
it("should remove subscribers by calling from subscriber's callback", function(){
var spy = sinon.spy(),
spy2 = sinon.spy(),
catched = false;
mediator.subscribe("test", function(){
mediator.remove("test");
});
mediator.subscribe("test", spy);
mediator.subscribe("test", spy2);
try{
mediator.publish("test");
}
catch (e){
catched = true;
}
expect(catched).to.be.false;
expect(spy).not.called;
expect(spy2).not.called;
});
it("should remove subscriber by calling from its callback", function(){
var remover = function(){
mediator.remove("test", sub.id);
};
var spy = sinon.spy(),
spy2 = sinon.spy(),
catched = false,
self = this;
var sub = mediator.subscribe("test", remover);
mediator.subscribe("test", spy);
mediator.subscribe("test", spy2);
try{
mediator.publish("test");
}
catch (e){
catched = true;
}
expect(catched).to.be.false;
expect(spy).to.called;
expect(spy2).to.called;
var remover = sinon.spy(remover);
mediator.publish("test");
expect(remover).not.to.called;
expect(spy).to.called;
expect(spy2).to.called;
});
});

@@ -170,0 +217,0 @@

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