Comparing version 0.0.4 to 0.1.0
// 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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
13787
12
386
0