From 1eac83465c4dfbd9fade61c1be38bbeafb2ce129 Mon Sep 17 00:00:00 2001 From: Arthur Gunn Date: Thu, 3 Mar 2016 14:51:42 +1300 Subject: [PATCH 1/3] Eliminate dependencies on jquery, and underscore. --- lib/client.js | 12 ++++++++++-- package.js | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/client.js b/lib/client.js index 2a9a15d..09eca42 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1,6 +1,14 @@ Meteor.startup(function() { - var dom = $('script[type="text/inject-data"]', document); - var injectedDataString = $.trim(dom.text()); + var injectedDataString = "" + var scriptTags = document.getElementsByTagName("script"); + + for (var i = 0; i < scriptTags.length; i++) { + if (scriptTags[i].getAttribute("type") == "text/inject-data") { + injectedDataString = scriptTags[i].innerHTML.replace(/(^\s+|\s+$)/g, ""); + break; + } + } + InjectData._data = InjectData._decode(injectedDataString) || {}; }); diff --git a/package.js b/package.js index 2102de2..49627d8 100644 --- a/package.js +++ b/package.js @@ -37,8 +37,8 @@ Package.onTest(function(api) { function configure (api) { api.versionsFrom('METEOR@0.9.3'); - api.use(['ejson', 'underscore'], ['server', 'client']); - api.use('jquery', 'client'); + api.use('ejson', ['server', 'client']); + api.use('underscore', 'server'); api.addFiles([ 'lib/inject.html', From 4b6909821bcbbc470a79f22c124e5d71bc8fca60 Mon Sep 17 00:00:00 2001 From: Arthur Gunn Date: Thu, 3 Mar 2016 19:27:02 +1300 Subject: [PATCH 2/3] Eliminate underscore dependency. --- lib/inject.html | 1 - lib/server.js | 11 +++++------ package.js | 5 ----- tests/integration.js | 8 +++++--- 4 files changed, 10 insertions(+), 15 deletions(-) delete mode 100644 lib/inject.html diff --git a/lib/inject.html b/lib/inject.html deleted file mode 100644 index 6d2b002..0000000 --- a/lib/inject.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/lib/server.js b/lib/server.js index 82043cf..7ec236a 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1,9 +1,6 @@ var http = Npm.require('http'); -var templateText = Assets.getText('lib/inject.html'); -var injectDataTemplate = _.template(templateText); - -// custome API +// custom API InjectData.pushData = function pushData(res, key, value) { if(!res._injectPayload) { res._injectPayload = {}; @@ -15,7 +12,9 @@ InjectData.pushData = function pushData(res, key, value) { InjectData.getData = function getData(res, key) { if(res._injectPayload) { - return _.clone(res._injectPayload[key]); + var data = res._injectPayload[key]; + var clonedData = EJSON.parse(EJSON.stringify(data)); + return clonedData; } else { return null; } @@ -50,7 +49,7 @@ InjectData._hijackWriteIfNeeded = function(res) { // inject data var data = InjectData._encode(res._injectPayload); - var injectHtml = injectDataTemplate({data: data}); + var injectHtml = ''; // if this is a buffer, convert it to string chunk = chunk.toString(); diff --git a/package.js b/package.js index 49627d8..bd12f87 100644 --- a/package.js +++ b/package.js @@ -38,11 +38,6 @@ function configure (api) { api.versionsFrom('METEOR@0.9.3'); api.use('ejson', ['server', 'client']); - api.use('underscore', 'server'); - - api.addFiles([ - 'lib/inject.html', - ], 'server', {isAsset: true}); api.addFiles([ 'lib/namespace.js', diff --git a/tests/integration.js b/tests/integration.js index b65297a..f74da0f 100644 --- a/tests/integration.js +++ b/tests/integration.js @@ -39,9 +39,11 @@ Tinytest.add( }; Picker.route(path, function(params, req, res, next) { - _.each(sendingData, function(val, key) { - InjectData.pushData(res, key, val); - }); + for (var key in sendingData) { + if (sendingData.hasOwnProperty(key)) { + console.log(key, sendingData[key]); + } + } next(); }); From 09c08d5b7c6fe41bed5e8d225c3f761eae26f394 Mon Sep 17 00:00:00 2001 From: Arthur Gunn Date: Thu, 3 Mar 2016 20:40:53 +1300 Subject: [PATCH 3/3] Fix tests. --- tests/integration.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/integration.js b/tests/integration.js index f74da0f..63d83a8 100644 --- a/tests/integration.js +++ b/tests/integration.js @@ -41,7 +41,7 @@ Tinytest.add( Picker.route(path, function(params, req, res, next) { for (var key in sendingData) { if (sendingData.hasOwnProperty(key)) { - console.log(key, sendingData[key]); + InjectData.pushData(res, key, sendingData[key]); } } next(); @@ -132,7 +132,8 @@ function getInjectedData(path) { var url = urlResolve(process.env.ROOT_URL, path); var res = HTTP.get(url); - var matched = res.content.match(/data">(.*)<\/script/); + var matched = res.content.match(/data">(.*?)<\/script/); + if(matched) { var encodedData = matched[1]; return InjectData._decode(encodedData);