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

piggie

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

piggie - npm Package Compare versions

Comparing version 0.0.4 to 0.1.0

lib/event-bus.js

39

lib/bridge.js
// Dependencies
var Response = require( './response' );
var PiggieEvents = require( './event-bus' ),
Response = require( './response' );
// Handlers hash
var handlers = {};
/**
* Resets the handlers hash
* Piggie constructor
*/
var reset = function reset () {
handlers = {};
var Piggie = function Piggie () {
this.handlers = {};
};
// Extend PiggieEvents
Piggie.prototype = new PiggieEvents();
/**
* Register handler
*/
var register = function register ( path, handler ) {
Piggie.prototype.register = function register ( path, handler ) {
if ( handlers.hasOwnProperty( path ) ) {
if ( this.handlers.hasOwnProperty( path ) ) {
throw new Error( 'Handler already exists for path: ' + path );
} else {
handlers[ path ] = handler;
this.handlers[ path ] = handler;
}

@@ -30,3 +31,3 @@

*/
var execute = function execute ( key, path, data ) {
Piggie.prototype._execute = function _execute ( key, path, data ) {
var response = ( key instanceof Response ? key : new Response( key ) );

@@ -45,4 +46,4 @@

if ( handlers[ path ] ) {
handlers[ path ]( data, response );
if ( this.handlers[ path ] ) {
this.handlers[ path ]( data, response );
return response;

@@ -55,5 +56,11 @@ } else {

/**
* Resets the Piggie interface
*/
Piggie.prototype._reset = function _reset () {
this.handlers = {};
this.removeAllListeners();
};
// Exports
module.exports.register = register;
module.exports.execute = execute;
module.exports.reset = reset;
module.exports = Piggie;

@@ -15,5 +15,8 @@ /**

fail: function fail ( error, code ) {
// Android
if ( typeof window != "undefined" && window.android ) {
window.android.fail( this.key, ( code || null ), error.name, error.message );
}
// iOS
// TODO
},

@@ -25,5 +28,8 @@

success: function success ( data ) {
// Android
if ( typeof window != "undefined" && window.android ) {
window.android.success( this.key, data );
}
// iOS
// TODO
}

@@ -30,0 +36,0 @@

{
"name": "piggie",
"version": "0.0.4",
"version": "0.1.0",
"main": "app.js",

@@ -5,0 +5,0 @@ "dependencies": {},

var sinon = require( 'sinon' ),
assert = require( 'assert' ),
piggie = require( '../index' ),
Piggie = require( '../index' ),
Response = process.env.PIGGIE_COVERAGE ? require( '../lib-cov/response' ) : require( '../lib/response' );
var piggie = new Piggie();
describe( 'Data in', function() {
beforeEach( function () {
piggie.reset();
piggie._reset();
window = {
android: {
fail: function() {},
success: function() {},
event: function() {}
}
};
} );

@@ -22,3 +32,3 @@

// Send the request
piggie.execute( dummyResponse, 'event' );
piggie._execute( dummyResponse, 'event' );

@@ -38,3 +48,3 @@ } );

// Send the request
piggie.execute( dummyResponse, 'event', JSON.stringify( dummyData ) );
piggie._execute( dummyResponse, 'event', JSON.stringify( dummyData ) );

@@ -54,3 +64,3 @@ } );

// Send the request
piggie.execute( dummyResponse, 'event', JSON.stringify( dummyData ) );
piggie._execute( dummyResponse, 'event', JSON.stringify( dummyData ) );

@@ -69,3 +79,3 @@ } );

// Send the request
piggie.execute( dummyResponse, 'event', JSON.stringify( dummyData ) );
piggie._execute( dummyResponse, 'event', JSON.stringify( dummyData ) );

@@ -87,3 +97,3 @@ } );

// Send the request
piggie.execute( dummyResponse, 'event', JSON.stringify( dummyData ) );
piggie._execute( dummyResponse, 'event', JSON.stringify( dummyData ) );

@@ -106,3 +116,3 @@ } );

// Send the request
piggie.execute( dummyResponse, 'event', JSON.stringify( dummyData ) );
piggie._execute( dummyResponse, 'event', JSON.stringify( dummyData ) );

@@ -121,3 +131,3 @@ } );

// Send the request and spy on the fail callback
piggie.execute( dummyResponse, 'event', dummyData );
piggie._execute( dummyResponse, 'event', dummyData );
assert( responseFailSpy.called );

@@ -124,0 +134,0 @@

var sinon = require( 'sinon' ),
assert = require( 'assert' ),
piggie = require( '../index' ),
Piggie = require( '../index' ),
Response = process.env.PIGGIE_COVERAGE ? require( '../lib-cov/response' ) : require( '../lib/response' );
var piggie = new Piggie();
describe( 'Data out', function() {
beforeEach( function () {
piggie.reset();
piggie._reset();
window = {
android: {
fail: function() {},
success: function() {},
event: function() {}
}
};
} );

@@ -24,3 +34,3 @@

// Send the request and spy on the success callback
piggie.execute( dummyResponse, 'event' );
piggie._execute( dummyResponse, 'event' );
assert( responseSuccessSpy.calledWith( dummyData ) );

@@ -42,3 +52,3 @@

// Send the request and spy on the success callback
piggie.execute( dummyResponse, 'event' );
piggie._execute( dummyResponse, 'event' );
assert( responseSuccessSpy.calledWith( dummyData ) );

@@ -59,3 +69,3 @@

// Send the request and spy on the success callback
piggie.execute( dummyResponse, 'event' );
piggie._execute( dummyResponse, 'event' );
assert( responseSuccessSpy.calledWith( dummyData ) );

@@ -79,3 +89,3 @@

// Send the request and spy on the success callback
piggie.execute( dummyResponse, 'event' );
piggie._execute( dummyResponse, 'event' );
assert( responseSuccessSpy.calledWith( dummyData ) );

@@ -100,3 +110,3 @@

// Send the request and spy on the success callback
piggie.execute( dummyResponse, 'event' );
piggie._execute( dummyResponse, 'event' );
assert( responseSuccessSpy.calledWith( dummyData ) );

@@ -103,0 +113,0 @@

var sinon = require( 'sinon' ),
assert = require( 'assert' ),
piggie = require( '../index' ),
Piggie = require( '../index' ),
Response = process.env.PIGGIE_COVERAGE ? require( '../lib-cov/response' ) : require( '../lib/response' );
var piggie = new Piggie();
describe( 'Handler', function() {
beforeEach( function() {
piggie.reset();
piggie._reset();
window = {
android: {
fail: function() {},
success: function() {},
event: function() {}
}
};
} );

@@ -18,3 +28,3 @@

// Test the handler calls the fail callback
piggie.execute( dummyResponse, 'event' );
piggie._execute( dummyResponse, 'event' );
assert( responseFailSpy.called );

@@ -21,0 +31,0 @@

Sorry, the diff of this file is not supported yet

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