Skip to content

Commit

Permalink
Tweak closure that wraps the serialized output
Browse files Browse the repository at this point in the history
This has no affect on app code, it's merely a rename of a local variable
from `g` to `root`.
  • Loading branch information
ericf committed Dec 4, 2013
1 parent b250ff3 commit d8ca572
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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));
```

Expand Down
6 changes: 3 additions & 3 deletions lib/exposed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -87,11 +87,11 @@ Exposed.prototype.toString = function () {

return [
'',
'(function (g) {',
'(function (root) {',
'// -- Namespaces --',
namespaces.join('\n'),
'',
'// -- Exposed --',
'// -- Data --',
exposed.join('\n'),
'}(this));',
''
Expand Down

0 comments on commit d8ca572

Please sign in to comment.