connection-state
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -1,34 +0,2 @@ | ||
var listenable = function () { | ||
var listeners = []; | ||
var findIndex = function (callback) { | ||
return listeners.findIndex(function (listener) { return listener.callback === callback; }); | ||
}; | ||
var addListener = function (callback, options) { | ||
if (options === void 0) { options = {}; } | ||
// Prevent duplicate listeners | ||
if (findIndex(callback) >= 0) { | ||
return; | ||
} | ||
listeners.push({ callback: callback, options: options }); | ||
}; | ||
var removeListener = function (callback) { | ||
var listenerIndex = findIndex(callback); | ||
if (listenerIndex >= 0) { | ||
listeners.splice(listenerIndex, 1); | ||
} | ||
}; | ||
var emit = function (data) { | ||
listeners.forEach(function (listener) { | ||
listener.callback(data); | ||
if (listener.options.once) { | ||
removeListener(listener.callback); | ||
} | ||
}); | ||
}; | ||
return { | ||
addListener: addListener, | ||
removeListener: removeListener, | ||
emit: emit, | ||
}; | ||
}; | ||
import { listenable } from 'custom-listenable'; | ||
@@ -35,0 +3,0 @@ var connectionState = function (options) { |
'use strict'; | ||
var listenable = function () { | ||
var listeners = []; | ||
var findIndex = function (callback) { | ||
return listeners.findIndex(function (listener) { return listener.callback === callback; }); | ||
}; | ||
var addListener = function (callback, options) { | ||
if (options === void 0) { options = {}; } | ||
// Prevent duplicate listeners | ||
if (findIndex(callback) >= 0) { | ||
return; | ||
} | ||
listeners.push({ callback: callback, options: options }); | ||
}; | ||
var removeListener = function (callback) { | ||
var listenerIndex = findIndex(callback); | ||
if (listenerIndex >= 0) { | ||
listeners.splice(listenerIndex, 1); | ||
} | ||
}; | ||
var emit = function (data) { | ||
listeners.forEach(function (listener) { | ||
listener.callback(data); | ||
if (listener.options.once) { | ||
removeListener(listener.callback); | ||
} | ||
}); | ||
}; | ||
return { | ||
addListener: addListener, | ||
removeListener: removeListener, | ||
emit: emit, | ||
}; | ||
}; | ||
var customListenable = require('custom-listenable'); | ||
var connectionState = function (options) { | ||
if (options === void 0) { options = {}; } | ||
var listener = listenable(); | ||
var listener = customListenable.listenable(); | ||
var _a = options.endpoints, endpoints = _a === void 0 ? [] : _a; | ||
@@ -41,0 +9,0 @@ if (endpoints.length > 0) { |
{ | ||
"name": "connection-state", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Detect online and offline network state.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
Sorry, the diff of this file is not supported yet
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
9012
71