From d8ca572d5c5dd231ac62c61408a6daf05e478c9e Mon Sep 17 00:00:00 2001 From: Eric Ferraiuolo Date: Wed, 4 Dec 2013 12:19:01 -0500 Subject: [PATCH] Tweak closure that wraps the serialized output This has no affect on app code, it's merely a rename of a local variable from `g` to `root`. --- HISTORY.md | 5 +++++ README.md | 16 ++++++++-------- lib/exposed.js | 6 +++--- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 3b2d414..937e141 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -8,6 +8,11 @@ NEXT * Added `.npmignore` file. ([#15][]) +* Tweaked closure that's wrapped around the serialized data and namespace + initialization. There's no affect on app code, this is merely renaming a local + variable from `g` to `root` which is the reference to the root or global + object that the namespaces hang off of. + [#15]: https://github.com/yahoo/express-state/issues/15 [#17]: https://github.com/yahoo/express-state/issues/17 diff --git a/README.md b/README.md index cf2e938..133d559 100644 --- a/README.md +++ b/README.md @@ -313,17 +313,17 @@ console.log(app.locals.state.toString()); The output of the `console.log()` call would be: ```javascript -(function (g) { +(function (root) { // -- Namespaces -- -g.foo || (g.foo = {}); -g.a || (g.a = {}); -g.a.very || (g.a.very = {}); -g.a.very.big || (g.a.very.big = {}); +root.foo || (root.foo = {}); +root.a || (root.a = {}); +root.a.very || (root.a.very = {}); +root.a.very.big || (root.a.very.big = {}); // -- Exposed -- -g.foo = {"bar":"bar"}; -g.foo.baz = /baz/; -g.a.very.big.ns = function () { return 'bla'; }; +root.foo = {"bar":"bar"}; +root.foo.baz = /baz/; +root.a.very.big.ns = function () { return 'bla'; }; }(this)); ``` diff --git a/lib/exposed.js b/lib/exposed.js index 2e42fe1..d13fd6c 100644 --- a/lib/exposed.js +++ b/lib/exposed.js @@ -64,7 +64,7 @@ Exposed.prototype.toString = function () { this.__namespaces__.forEach(function (namespace) { var parts = namespace.split('.'), leafPart = parts.pop(), - nsPart = 'g'; + nsPart = 'root'; // Renders the JavaScript to instantiate each namespace as needed, and // does so efficiently making sure to only instantiate each part of the @@ -87,11 +87,11 @@ Exposed.prototype.toString = function () { return [ '', - '(function (g) {', + '(function (root) {', '// -- Namespaces --', namespaces.join('\n'), '', - '// -- Exposed --', + '// -- Data --', exposed.join('\n'), '}(this));', ''