Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make the non-DOM things work with node.js #23

Closed
RandomEtc opened this issue Apr 19, 2011 · 9 comments
Closed

make the non-DOM things work with node.js #23

RandomEtc opened this issue Apr 19, 2011 · 9 comments

Comments

@RandomEtc
Copy link
Contributor

Might be nice to have a package.json and npm availability too.

e.g. https://github.com/documentcloud/underscore/blob/master/package.json

Here's how underscore handles being attached to either window or loaded via require():

  // Establish the root object, `window` in the browser, or `global` on the server.
  var root = this;

  // (skip a bit)

  // Create a safe reference to the Underscore object for use below.
  var _ = function(obj) { return new wrapper(obj); };

  // Export the Underscore object for **CommonJS**, with backwards-compatibility
  // for the old `require()` API. If we're not in CommonJS, add `_` to the
  // global object.
  if (typeof module !== 'undefined' && module.exports) {
    module.exports = _;
    _._ = _;
  } else {
    root._ = _;
  }

Should be quick and simple to add something similar for us, and allow use of Locations, Coordinates, Points etc on the server side. Later we can figure out how to render static images, perhaps using https://github.com/learnBoost/node-canvas/

@migurski
Copy link
Contributor

Do you think npm is the right way to consume package.json, or is the format well-described enough that we could use something else if we wanted? Like, if we wanted to write some minimal Python thing to consume those description files and prepare releases, could we? The "sudo sh" part of installing npm and what you're described of their fractious relationship with brew is making me a bit uncomfortable, and I think that Python might be a more universally-usable approach here.

Also ". = _;" is just sad panda.

@RandomEtc
Copy link
Contributor Author

npm would only be required for distributing with npm. We can use whatever we like to read package.json and post releases elsewhere. I don't think there's anything fundamentally wrong with npm, I think the author(s) know exactly what they're doing ( I don't think brew is perfect either).

@tmcw
Copy link
Contributor

tmcw commented May 3, 2011

There isn't much blocking this from happening quickly. Just opened #25 to remove some alert() calls, and I've got a package.json in the works, though the underlying architecture I'm not sure about yet.

@tmcw
Copy link
Contributor

tmcw commented May 9, 2011

I've started on a basic package.json and added it to a branch cleverly titled package.json - I'll test it out with some server-side stuff this week and figure what sort of separation between the DOM parts and this should be.

@tmcw
Copy link
Contributor

tmcw commented May 9, 2011

Okay, the exports branch is ready for a quick test - basically just does a module.exports if module and module.exports is available. The underscore method seems a little more stable, but right now we're doing scoping differently. This branch/commit would precede a push to rename com.modestmaps to MM and add noConflict functionality.

@RandomEtc
Copy link
Contributor Author

Looks good... I had wondered if it might be as simple as module.exports = MM but it's probably better to explicitly export node-compatible things and leave DOM-only code behind for now, as you have. These are the most readily testable classes too, so that's nice.

@tmcw
Copy link
Contributor

tmcw commented May 9, 2011

Yeah - I think that if we have some way of blocking out server-side use of DOM-stuff, but until then there shouldn't be a hole you can fall down and get an exception because window doesn't exist.

@tmcw
Copy link
Contributor

tmcw commented Jun 3, 2011

I've added modestmaps to npm - if you guys have usernames, I can add you as owners.

@RandomEtc
Copy link
Contributor Author

I'm randometc (lowercase) on npm. I just added a node example on master in 8ce3302 and it works very nicely for what I had in mind when I opened this issue, so I'm closing it :)

I also modified package.json just now because npm install failed for me using the 1.0.x syntax for specifying the version number of uglify. Using the tilde syntax worked so I just went with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants