Thanks for all your replies guys, but I don't see much point in continuing
this discussion as as far as I could understand, I would not recommend
backbone for anyone to use on the server side with node. Point taken. :)
On the other hand, this led me to a different question. Namely, the biggest
advantage I've seen in using Node for my project was to code only once
almost all my applications, and have the same models and validation ready
both for the browser and the server. As Backbone is great for the browser,
but performs badly on the server, what would you recommend? I'm interested
in to-be-welded-together proposals too.
thanks
2012. március 20., kedd 12:12:57 UTC+1 időpontban Bika a következőt írta:
>
> hi,
>
> I'm trying to use backbone for "everything" on the server side too, and
> got stuck with doing a proper validation. The problem is that backbone's
> validate method return a boolean, and the validation mechanics should be
> implemented inside of it, but with node these mechanics are asynchronous,
> thus the validate method returns before evaluating my code.
>
> Here is a code sample that illustrates well my setup:
>
> Backbone.Model.extend({
> validate: function(){
> var result;
> Jobs._withCollection(function(err, collection){
> collection.count(query, function(count){
> result = count > 1 ? "Job already exist" : null;
> });
> })
> return result;
> }
> })
>
> I might be able to improve this a little bit, but I'm not sure if this
> would work:
>
> function _validate(){
> Jobs._withCollection(function(err, collection){
> collection.count(query, function(count){
> yield count > 1 ? "Job already exist" : null;
> });
> })
> }
>
> Backbone.Model.extend({
> validate: function(){
> return _validate.call(this);
> }
> })
>
> Especially not for a bit more complex situations where I use async for
> example, and the return value is set in the last callback of async, like
> here (this is obviously wrong as res is null at return):
>
> Backbone.Model.extend({
> validate: function(){
> var res;
> async.parallel([
> .. do stuff ..
> ], function(err, results){
> res = results;
> })
> return results;
> }
> })
>
> Any ideas?
>
> Viktor
> close
>
>
> close
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en