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

Feature Request: add clientRead option #58

Closed tommedema closed 13 years ago

tommedema commented 13 years ago

I really like the clientWrite option (it's actually a must for me to set this to false).

I'd like to request another feature: clientRead. This sets whether variable syncing is enabled, it defaults to true (current behavior). By setting is to false, no client<>server messages are sent as variables are only kept on the server side.

There are a couple of reasons why I would really like to see this option:

  1. There are many variables that both the server and client do need, but that the client only needs at certain times and not at all times. Thus, immediately syncing any changes from the server to the client causes unnecessary traffic if the client is not in need of that variable at that time. Instead, the client can simply call a server method such as getSomeVar() to get the variable when it does need it.
  2. A server side variable that is accessed on the client side at any point in time is not guaranteed to be in sync, due to the time delay. However, a function call, such as getSomeVar() does guarantee that the client receives an up-to-date value. Thus, I believe it is good practice to use functions rather than direct remote variable access.
  3. It is very useful to use the now scope of a client as the client's properties. Eg. this.now.id for the client's identifier. Many of these properties are not needed at all by the client. Thus, the server would have to create another server-only scope for this client to avoid unnecessary bandwidth. This is very troublesome and makes things more complex.
  4. If using the now scope as the client's properties, one might add properties here that should be hidden on the client side. Eg. this.now.password - setting this option to false would allow such behavior.

So, I'd really like to see a clientRead option (which should default to true, although I personally will set it to false).

ericz commented 13 years ago

Hi tom,

I do see the usefulness of this feature but the implementation of this is more tricky than the clientWrite feature. We're not planning on implementing this now for that reason, but if I hear more requests for this feature, I'll definitely look into it further / reopen the issue.

Eric

ericz commented 13 years ago

@tommedema

Also, you can use the this.user object to store data that cannot be read by the client side (and won't be synced of course)

So if I do this.user.x = 3; then whenever this.user is available (in any function call, for example) then that value will still be accessible.

tommedema commented 13 years ago

@ericz, will do, the only thing I'm worried about is that the server side will still constantly poll for new variables which are never going to get added anyway -- right? Thanks.

ericz commented 13 years ago

The server never polls, because we can use the node-proxy v8 extension, we can get actual events for when variables are created/changed.

However the client does indeed poll.

Eric

On Wed, May 11, 2011 at 11:35 AM, tommedema < reply@reply.github.com>wrote:

@ericz, will do, the only thing I'm worried about is that the server side will still constantly poll for new variables which are never going to get added anyway -- right? Thanks.

Reply to this email directly or view it on GitHub: https://github.com/Flotype/now/issues/58#comment_1142159

510-691-3951 EECS Student at UC Berkeley http://ericzhang.com