Flotype / now

NowJS makes it easy to build real-time web apps using JavaScript
http://www.nowjs.com
MIT License
1.91k stars 175 forks source link

Persistent server-side object for storing data server side #75

Closed eirikb closed 13 years ago

eirikb commented 13 years ago

Hello.

This is a simple example of how this.user can become a persistent server-side object. Example of usage: index.html:

<script type="text/javascript">
    now.ready(function() {
        now.hello('Hello, world');
        now.world(function(msg) {
            console.log(msg);
        });
    });
</script>

server.js:

var everyone = nowjs.initialize(server);

everyone.now.hello = function(msg) {
    this.user.test = msg;
};

everyone.now.world = function(callback) {
    callback(this.user.test);
};
tommedema commented 13 years ago

Isn't there already a this.user object within the scope of the called function?

eirikb commented 13 years ago

Yes, but it is sent in every time, so it is not persistent on the server side. As in my example would not work since test would no longer exists in the world-function.

sridatta commented 13 years ago

This is a good idea, eirikb . There are several other places where we create a one-time user object. I'll change those other places to use a persistent user object and then merge your pull request.

eirikb commented 13 years ago

Awesome

sridatta commented 13 years ago

Implemented in github master. npm soon.