exaquark-js
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -11,3 +11,3 @@ 'use strict'; | ||
var _distance = require('./utils/distance'); | ||
var _helpers = require('./helpers'); | ||
@@ -69,3 +69,3 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
this.params = options.params || {}; | ||
this.state = null; // holds the latest client state | ||
this.state = null; // holds the latest client entityState | ||
@@ -130,3 +130,5 @@ // this.heartbeatTimer = null | ||
key: 'disconnect', | ||
value: function disconnect(callback, code, reason) {} | ||
value: function disconnect(callback, code, reason) { | ||
this.conn.close(); | ||
} | ||
@@ -186,2 +188,3 @@ /** | ||
(0, _private.log)(this.logger, 'onConnClose', event); | ||
this.disconnect(); | ||
clearInterval(this.clientStateInterval); | ||
@@ -267,4 +270,4 @@ } | ||
value: function addNeighbor(n) { | ||
this.neighborHash[n.iid] = n; | ||
this.trigger('neighbor:enter', n); | ||
this.neighborHash[n.iid] = n; | ||
} | ||
@@ -274,4 +277,4 @@ }, { | ||
value: function updateNeighbor(n) { | ||
this.neighborHash[n.iid] = n; | ||
this.trigger('neighbor:updates', n); | ||
this.neighborHash[n.iid] = n; | ||
} | ||
@@ -281,4 +284,4 @@ }, { | ||
value: function removeNeighbor(n) { | ||
this.trigger('neighbor:remove', n); | ||
delete this.neighborHash[n.iid]; | ||
this.trigger('neighbor:leave', n); | ||
} | ||
@@ -311,3 +314,3 @@ }, { | ||
value: function neighbors(format) { | ||
if (format && format === 'Array') return (0, _private.dictionaryToArray)(this.neighborHash);else return this.neighborHash; | ||
return (0, _helpers.dictionaryToArray)(this.neighborHash); | ||
} | ||
@@ -343,2 +346,5 @@ }, { | ||
value: function askForNeighbors() { | ||
if (!this.canPush()) { | ||
return; | ||
} | ||
var payload = { | ||
@@ -351,34 +357,2 @@ method: 'ask:neighbor', | ||
} | ||
/** | ||
* Returns the distance between two entities | ||
* @param {string} [options.units] - the unit of measurement. Defaults to meters | ||
*/ | ||
}, { | ||
key: 'getDistanceBetweenEntities', | ||
value: function getDistanceBetweenEntities(entityOne, entityTwo, options) { | ||
return (0, _distance.distanceOnSphere)(entityOne.geo.lat, entityOne.geo.lng, entityTwo.geo.lat, entityTwo.geo.lng); | ||
} | ||
/** | ||
* Gets a list of neighbors within a specified distance | ||
* @param {number} distance | ||
* @param {string} [options.listType] - the list format to return. Defaults to Dictionary. Options: "Array" | "Dict" | ||
* @param {string} [options.units] - the unit of measurement. Defaults to meters | ||
*/ | ||
}, { | ||
key: 'getNeighborsByMaxDistance', | ||
value: function getNeighborsByMaxDistance(distance) { | ||
var _this6 = this; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var filteredList = (0, _private.dictionaryToArray)(this.neighborHash).filter(function (x) { | ||
return distance >= (0, _distance.distanceOnSphere)(_this6.state.geo.lat, _this6.state.geo.lng, x.geo.lat, x.geo.lng); | ||
}); | ||
if (options.listType === 'Array') return filteredList;else return (0, _private.arrayToDictionary)(filteredList); | ||
} | ||
}]); | ||
@@ -385,0 +359,0 @@ |
@@ -8,17 +8,2 @@ "use strict"; | ||
logger(msg, data); | ||
}; | ||
// Converts a dictionary to an array | ||
_exports.dictionaryToArray = function (dict) { | ||
return Object.keys(dict).map(function (key) { | ||
return dict[key]; | ||
}); | ||
}; | ||
// Converts a dictionary to an array | ||
_exports.arrayToDictionary = function (arr) { | ||
return arr.reduce(function (map, obj) { | ||
map[obj.iid] = obj; | ||
return map; | ||
}, {}); | ||
}; |
{ | ||
"name": "exaquark-js", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "JS wrapper for exaquark.com", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -34,1 +34,11 @@ # exaQuark JS | ||
You can see a demo of the library in action in `demo`. See `demo/README.md` for instructions. | ||
## ChangeLog | ||
##### 1.0.8 | ||
- Adding changes for customState | ||
##### 1.0.7 | ||
- Added `getDistanceBetweenEntities()` & `getNeighborsByMaxDistance()` |
@@ -1,3 +0,3 @@ | ||
import { log, dictionaryToArray, arrayToDictionary } from './utils/private' | ||
import { distanceOnSphere } from './utils/distance' | ||
import { log } from './utils/private' | ||
import { dictionaryToArray } from './helpers' | ||
@@ -53,3 +53,3 @@ const loadJSONP = (() => { | ||
this.params = options.params || {} | ||
this.state = null // holds the latest client state | ||
this.state = null // holds the latest client entityState | ||
@@ -96,3 +96,3 @@ // this.heartbeatTimer = null | ||
disconnect (callback, code, reason) { | ||
this.conn.close() | ||
} | ||
@@ -135,2 +135,3 @@ | ||
log(this.logger, 'onConnClose', event) | ||
this.disconnect() | ||
clearInterval(this.clientStateInterval) | ||
@@ -188,12 +189,12 @@ } | ||
addNeighbor (n) { | ||
this.neighborHash[n.iid] = n | ||
this.trigger('neighbor:enter', n) | ||
this.neighborHash[n.iid] = n | ||
} | ||
updateNeighbor (n) { | ||
this.neighborHash[n.iid] = n | ||
this.trigger('neighbor:updates', n) | ||
this.neighborHash[n.iid] = n | ||
} | ||
removeNeighbor (n) { | ||
this.trigger('neighbor:remove', n) | ||
delete this.neighborHash[n.iid] | ||
this.trigger('neighbor:leave', n) | ||
} | ||
@@ -218,4 +219,3 @@ push (eventName, payload) { | ||
neighbors (format) { | ||
if (format && format === 'Array') return dictionaryToArray(this.neighborHash) | ||
else return this.neighborHash | ||
return dictionaryToArray(this.neighborHash) | ||
} | ||
@@ -241,2 +241,3 @@ deepClone (object) { | ||
askForNeighbors () { | ||
if (!this.canPush()) { return } | ||
let payload = { | ||
@@ -249,25 +250,3 @@ method: 'ask:neighbor', | ||
} | ||
/** | ||
* Returns the distance between two entities | ||
* @param {string} [options.units] - the unit of measurement. Defaults to meters | ||
*/ | ||
getDistanceBetweenEntities (entityOne, entityTwo, options) { | ||
return distanceOnSphere(entityOne.geo.lat, entityOne.geo.lng, entityTwo.geo.lat, entityTwo.geo.lng) | ||
} | ||
/** | ||
* Gets a list of neighbors within a specified distance | ||
* @param {number} distance | ||
* @param {string} [options.listType] - the list format to return. Defaults to Dictionary. Options: "Array" | "Dict" | ||
* @param {string} [options.units] - the unit of measurement. Defaults to meters | ||
*/ | ||
getNeighborsByMaxDistance (distance, options = {}) { | ||
let filteredList = dictionaryToArray(this.neighborHash) | ||
.filter(x => distance >= distanceOnSphere(this.state.geo.lat, this.state.geo.lng, x.geo.lat, x.geo.lng)) | ||
if (options.listType === 'Array') return filteredList | ||
else return arrayToDictionary(filteredList) | ||
} | ||
} | ||
export default exaQuark |
@@ -0,0 +0,0 @@ var exports = module.exports = {} |
@@ -7,14 +7,1 @@ var exports = module.exports = {} | ||
} | ||
// Converts a dictionary to an array | ||
exports.dictionaryToArray = function (dict) { | ||
return Object.keys(dict).map(key => dict[key]) | ||
} | ||
// Converts a dictionary to an array | ||
exports.arrayToDictionary = function (arr) { | ||
return arr.reduce(function (map, obj) { | ||
map[obj.iid] = obj | ||
return map | ||
}, {}) | ||
} |
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
25421
10
661
44