Closed tedsuo closed 13 years ago
This is not supported each page counts as one client and now namespaces are associated with a single client.
However, the now namespace can be partitioned as you wish. One widget could put properties in now.widgetOne while another can use properties placed in now.widgetTwo . Would that work for you?
Wonder if you could return now
from a closure, instead of directly set window.now
et al?
sridatta: hmmm, sounds like that would tie these apps together on the backend, correct? In my ideal world they would remain separate, and not need to be on the same subnet.
A related use case is that "now" is a pretty common word, so it's possible that there could be a conflict with another library trying to use the same namespace, such as prototype and jquery both using the $ namespace. I'm pretty sure you could solve this without providing multiple now's, and it would be easier.
@tedsuo It would make more sense to put each widget in an iframe, in which case the JS is sandboxed and multiple now connections for each widget would work.
I do agree with dvv's comment that returning a now object is much better than setting a window global.
@tommedema, @dvv
I am hesitant to change from setting a window global to returning a now object. Primarily that would break existing implementations using nowjs. So far I have not heard of any conflicting javascript library.
@ericz, since the project is so young, you should consider creating a mayor release if you wish to change the API or default behavior, (eg. disabling variable synching and to disable client-side writing by default).
Personally I think it's a bad idea to not implement improvements because it could break existing code at such an early stage.
I personally strongly agree to @tommedema. Should be no fear to split the community, as the changes to client code are not that huge. The benefits of having multiple contexts are clear, imho.
While for this I'm not that concerned, but for the notion of fear to make big changes I do agree with @tommedema - expanding onto this I feel the node.js community is use to the their libraries constantly evolving and changing, it is part of being the greatest and best - sometimes you have to break stuff to kick butt :P
Hmm alright I'll try to make this happen
Check out v0.7's latest commit -- with the following code, this can now be accomplished:
var nowjs = require('now');
nowjs.initialize(server, {scope: 'myObj.scope'});
It's actually just one of the configurable options, so just add it into the options
object that you're passing in.
My use case is a page with several widgets on it, all powered by nowjs but with different backends. Currently loading the second widget would overwrite the now namespace of the first widget.