Permalink
Browse files

Finished removal of lodash dependency.

  • Loading branch information...
michaellperry committed Oct 18, 2015
1 parent 5adc84e commit 942fe55e39a5cb919d2011758fa4f344c3315a51
Showing with 31 additions and 24 deletions.
  1. +1 −2 bower.json
  2. +0 −1 package.json
  3. +6 −7 src/jinaga.distributor.server.ts
  4. +1 −2 src/jinaga.mongo.ts
  5. +23 −8 src/memory.ts
  6. +0 −1 src/queryParser.ts
  7. +0 −3 tsd.json
View
@@ -20,7 +20,6 @@
],
"dependencies": {
"debug": "*",
- "engine.io-client": "~1.5.2",
- "lodash": "~3.10.1"
+ "engine.io-client": "~1.5.2"
}
}
View
@@ -32,7 +32,6 @@
"debug": "^2.2.0",
"engine.io": "^1.5.2",
"engine.io-client": "^1.5.2",
- "lodash": "^3.10.1",
"minimist": "^1.2.0",
"mongodb": "^2.0.43",
"requirejs": "^2.1.20"
@@ -4,7 +4,6 @@ import Interface = require("./interface");
import Query = Interface.Query;
import StorageProvider = Interface.StorageProvider;
import Coordinator = Interface.Coordinator;
-import _ = require("lodash");
import QueryInverter = require("./queryInverter");
import Inverse = QueryInverter.Inverse;
@@ -53,7 +52,7 @@ class JinagaConnection {
var query = Interface.fromDescriptiveString(message.query);
// TODO: This is incorrect. Each segment of the query should be executed.
this.distributor.storage.executeQuery(message.start, query, function (error: string, results: Array<Object>) {
- _.each(results, function (result: Object) {
+ results.forEach(function (result: Object) {
debug("Sending result");
this.socket.send(JSON.stringify({
type: "fact",
@@ -62,7 +61,7 @@ class JinagaConnection {
}, this);
}, this);
var inverses = QueryInverter.invertQuery(query);
- _.each(inverses, function (inverse: Inverse) {
+ inverses.forEach(function (inverse: Inverse) {
this.watches.push(new Watch(message.start, inverse.affected));
}, this);
}
@@ -81,14 +80,14 @@ class JinagaConnection {
distribute(fact: Object) {
debug("Distributing to " + this.socket.id);
- _.each(this.watches, function(watch) {
+ this.watches.forEach(function(watch) {
this.distributor.storage.executeQuery(fact, watch.affected, function (error: string, affected: Array<Object>) {
if (error) {
debug(error);
return;
}
- var some: any = _.some;
- if (some(affected, (obj: Object) => _.isEqual(obj, watch.start))) {
+ var some: any = Interface._some;
+ if (some(affected, (obj: Object) => Interface._isEqual(obj, watch.start))) {
debug("Sending fact");
this.socket.send(JSON.stringify({
type: "fact",
@@ -129,7 +128,7 @@ class JinagaDistributor implements Coordinator {
}
send(fact: Object, sender: any) {
- _.each(this.connections, function (connection: JinagaConnection) {
+ this.connections.forEach(function (connection: JinagaConnection) {
if (connection !== sender)
connection.distribute(fact);
}, this);
View
@@ -6,7 +6,6 @@ import Join = Interface.Join;
import PropertyCondition = Interface.PropertyCondition;
import computeHash = Interface.computeHash;
import isPredecessor = Interface.isPredecessor;
-import _ = require("lodash");
import Debug = require("debug");
var debug = Debug("jinaga.mongo");
@@ -41,7 +40,7 @@ class MongoSave {
private onFound(document) {
debug("Found " + JSON.stringify((document)));
- if (_.isEqual(this.fact, document.fact)) {
+ if (Interface._isEqual(this.fact, document.fact)) {
debug("It's a match");
this.isDone = true;
this.id = document._id;
View
@@ -10,7 +10,6 @@ import Coordinator = Interface.Coordinator;
import PropertyCondition = Interface.PropertyCondition;
import computeHash = Interface.computeHash;
import isPredecessor = Interface.isPredecessor;
-import _ = require("lodash");
class Node {
successors: { [role: string]: Array<Node> } = {};
@@ -87,18 +86,25 @@ class MemoryProvider implements StorageProvider {
}
else if (step instanceof PropertyCondition) {
var propertyCondition = <PropertyCondition>step;
- var template = { fact: {} };
- template.fact[propertyCondition.name] = propertyCondition.value;
- var nextNodes = _.filter(nodes, template);
+ var nextNodes: Array<Node> = [];
+ nodes.forEach(function (node) {
+ if (node.fact[propertyCondition.name] == propertyCondition.value) {
+ nextNodes.push(node);
+ }
+ });
nodes = nextNodes;
}
}
- result.bind(thisArg)(null, _.pluck(nodes, "fact"));
+ var facts: Array<Object> = [];
+ nodes.forEach(function (node) {
+ facts.push(node.fact);
+ });
+ result.bind(thisArg)(null, facts);
}
sendAllFacts() {
- _.each(this.queue, (item: {hash: number, fact: Object}) => {
+ this.queue.forEach((item: {hash: number, fact: Object}) => {
this.coordinator.send(item.fact, null);
});
}
@@ -109,14 +115,23 @@ class MemoryProvider implements StorageProvider {
this.coordinator.send(fact, null);
}
+ private findNodeWithFact(array: Array<Node>, fact: Object) : Node {
+ for(var index = 0; index < array.length; index++) {
+ if (Interface._isEqual(array[index].fact, fact)) {
+ return array[index];
+ }
+ }
+ return null;
+ }
+
private insertNode(fact: Object, source: any): Node {
var hash = computeHash(fact);
var array = this.nodes[hash];
if (!array) {
array = [];
this.nodes[hash] = array;
}
- var node = _.find(array, "fact", fact);
+ var node = this.findNodeWithFact(array, fact);
if (!node) {
var predecessors = {};
for (var field in fact) {
@@ -145,7 +160,7 @@ class MemoryProvider implements StorageProvider {
return null;
}
- return _.find(array, "fact", fact);
+ return this.findNodeWithFact(array, fact);
}
}
View
@@ -9,7 +9,6 @@ import ConditionalSpecification = Interface.ConditionalSpecification;
import ExistentialCondition = Interface.ExistentialCondition;
import Quantifier = Interface.Quantifier;
import InverseSpecification = Interface.InverseSpecification;
-import _ = require("lodash");
class ParserProxy implements Proxy {
constructor(
View
@@ -5,9 +5,6 @@
"path": "typings",
"bundle": "typings/tsd.d.ts",
"installed": {
- "lodash/lodash.d.ts": {
- "commit": "8f081073e6cb416f901b272810d8b04d6e01c9e0"
- },
"debug/debug.d.ts": {
"commit": "bb051830df88f5a55dcf06b7fe85bf6b62cc97f2"
},

0 comments on commit 942fe55

Please sign in to comment.