3 ms·
that you expose server-side implementation details on the client? This particular impl does it with javascript conditionals, but there's no reason the client m
by moe 16y ago
that you expose server-side implementation details on the client?
This particular impl does it with javascript conditionals, but there's no reason the client must see code that it never executes anyways. The equivalent of an #ifdef (ideally buried under a framework rug) goes a long way here.
Moreover a function does not even need to resolve to the same code on the client and the server. For example a model-validation function could evaluate to the actual validation logic on the server (incl. DB lookups etc.) and to a mere ajax RPC (calling that function on the server) on the client.
I could very well see a smart node serverside-library that let's you write one js file and then transparently mangles it as necessary before sending it to the client. The trick is to keep the magic down to a sane amount (slippery slope!) so that the end-result remains always predictable.
Luna
Yes, it seems luna is basically taking this approach.
What I don't like about luna is that it's not javascript and that it's, for my taste, taking the abstraction too far. It claims:
the client-side JavaScript, the server-side SQL, and everything in between
That's too much. Sure, for the developers it's comfortable to sidestep a whole cascade of hard problems simply by assuming control over everything ("My way or highway"). But this approach has not proven very successful in the javascript-world. We love small and pluggable components like jQuery or Backbone. The monoliths like Dojo or ExtJS tend to be too limiting on the My part of the way.
- jessedhillon 16y agoI agree with your comments about Luna. About the #ifdef proposal, I think a better solution might be that your server-side model object has a method like getSlaveObject() that gives you a version of the model that is acceptable to be seen on the client side.
- moe 16y agoYes, you are probably right, my examples were just meant to deliver the rough idea, not fully shaped solutions. Lots of room for experimentation and exploration in this space - exciting times ahead.