Skip to content

Commit

Permalink
Adding server side worker support & a blob placeholder (not utilized …
Browse files Browse the repository at this point in the history
…beyond an existence check)
  • Loading branch information
avoidwork committed Sep 29, 2015
1 parent 47ef3d4 commit 620fd25
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"no-negated-in-lhs": [2],
"no-nested-ternary": [0],
"no-new": [2],
"no-new-func": [2],
"no-new-func": [0],
"no-new-object": [2],
"no-new-require": [0],
"no-new-wrappers": [2],
Expand Down
14 changes: 10 additions & 4 deletions lib/haro.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @copyright 2015
* @license BSD-3-Clause
* @link http://haro.rocks
* @version 1.7.1
* @version 1.7.2
*/
"use strict";

Expand All @@ -17,6 +17,8 @@ const Set = !server ? global.Set : require("es6-set");
const fetch = !server ? global.fetch : require("node-fetch");
const deferred = !server ? global.deferred : require("tiny-defer");
const tuple = !server ? global.tuple : require("tiny-tuple");
const Blob = !server ? global.Blob : require("Blob");
const Worker = !server ? global.Worker : require("webworker-threads").Worker;
const r = [8, 9, "a", "b"];
const regex = {
querystring: /\?.*/,
Expand Down Expand Up @@ -185,6 +187,10 @@ function onmessage (ev) {
}

postMessage(JSON.stringify(result));

if (server && typeof self !== "undefined") {
self.close();
}
}

function patch (ogdata = {}, data = {}, key = "", overwrite = false) {
Expand Down Expand Up @@ -1073,11 +1079,11 @@ function factory (data = null, config = {}, indexes = []) {
setIndexValue.toString(),
setIndex.toString(),
cast.toString(),
"onmessage = " + onmessage.toString() + ";"
(!server ? "" : "this.") + "onmessage = " + onmessage.toString() + ";"
];

try {
obj.worker = global.URL.createObjectURL(blob(functions.join("\n")));
obj.worker = !server ? global.URL.createObjectURL(blob(functions.join("\n"))) : new Function(functions.join("\n"));
} catch (e) {
obj.worker = null;
}
Expand All @@ -1087,7 +1093,7 @@ function factory (data = null, config = {}, indexes = []) {
}

factory.transform = cast;
factory.version = "1.7.1";
factory.version = "1.7.2";

// Node, AMD & window supported
if (typeof exports !== "undefined") {
Expand Down
14 changes: 10 additions & 4 deletions lib/haro.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @copyright 2015
* @license BSD-3-Clause
* @link http://haro.rocks
* @version 1.7.1
* @version 1.7.2
*/
"use strict";

Expand All @@ -21,6 +21,8 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
var fetch = !server ? global.fetch : require("node-fetch");
var deferred = !server ? global.deferred : require("tiny-defer");
var tuple = !server ? global.tuple : require("tiny-tuple");
var Blob = !server ? global.Blob : require("Blob");
var Worker = !server ? global.Worker : require("webworker-threads").Worker;
var r = [8, 9, "a", "b"];
var regex = {
querystring: /\?.*/,
Expand Down Expand Up @@ -189,6 +191,10 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
}

postMessage(JSON.stringify(result));

if (server && typeof self !== "undefined") {
self.close();
}
}

function patch() {
Expand Down Expand Up @@ -1206,10 +1212,10 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
functions = undefined;

if (webWorker) {
functions = [createIndexes.toString(), keyIndex.toString(), setIndexValue.toString(), setIndex.toString(), cast.toString(), "onmessage = " + onmessage.toString() + ";"];
functions = [createIndexes.toString(), keyIndex.toString(), setIndexValue.toString(), setIndex.toString(), cast.toString(), (!server ? "" : "this.") + "onmessage = " + onmessage.toString() + ";"];

try {
obj.worker = global.URL.createObjectURL(blob(functions.join("\n")));
obj.worker = !server ? global.URL.createObjectURL(blob(functions.join("\n"))) : new Function(functions.join("\n"));
} catch (e) {
obj.worker = null;
}
Expand All @@ -1219,7 +1225,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
}

factory.transform = cast;
factory.version = "1.7.1";
factory.version = "1.7.2";

// Node, AMD & window supported
if (typeof exports !== "undefined") {
Expand Down
2 changes: 1 addition & 1 deletion lib/haro.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/haro.min.js.map

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "haro",
"version": "1.7.1",
"version": "1.7.2",
"description": "Harō is a modern immutable DataStore using Maps, Sets, Promises, & Tuples",
"main": "lib/haro.js",
"scripts": {
Expand Down Expand Up @@ -39,11 +39,13 @@
"tenso": "^1.5.1"
},
"dependencies": {
"Blob": "^0.10.0",
"es6-map": "^0.1.1",
"es6-promise": "^3.0.2",
"es6-set": "^0.1.1",
"node-fetch": "^1.2.1",
"tiny-defer": "^1.0.2",
"tiny-tuple": "^1.0.5"
"tiny-tuple": "^1.0.5",
"webworker-threads": "^0.6.0"
}
}
4 changes: 2 additions & 2 deletions src/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ function factory (data = null, config = {}, indexes = []) {
setIndexValue.toString(),
setIndex.toString(),
cast.toString(),
"onmessage = " + onmessage.toString() + ";"
(!server ? "" : "this.") + "onmessage = " + onmessage.toString() + ";"
];

try {
obj.worker = global.URL.createObjectURL(blob(functions.join("\n")));
obj.worker = !server ? global.URL.createObjectURL(blob(functions.join("\n"))) : new Function(functions.join("\n"));
} catch (e) {
obj.worker = null;
}
Expand Down
2 changes: 2 additions & 0 deletions src/intro.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const Set = !server ? global.Set : require("es6-set");
const fetch = !server ? global.fetch : require("node-fetch");
const deferred = !server ? global.deferred : require("tiny-defer");
const tuple = !server ? global.tuple : require("tiny-tuple");
const Blob = !server ? global.Blob : require("Blob");
const Worker = !server ? global.Worker : require("webworker-threads").Worker;
const r = [8, 9, "a", "b"];
const regex = {
querystring: /\?.*/,
Expand Down
4 changes: 4 additions & 0 deletions src/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ function onmessage (ev) {
}

postMessage(JSON.stringify(result));

if (server && typeof self !== "undefined") {
self.close();
}
}

function patch (ogdata = {}, data = {}, key = "", overwrite = false) {
Expand Down

0 comments on commit 620fd25

Please sign in to comment.