Search code examples
node.jsderbyjs

derbyjs running code on server from x-bind


I'm trying to run some server only code from an event on the client in derby.js I'm using x-bind to bind the event on the view like so:

<a href="#" x-bind="click: func">click me</a>

and on the app:

exports.func=function(e,el,next){
    // i want to run some server code here, but it runs on the client only
}

So:

  1. Can this be done in any way?
  2. if not, is there any way to use sockets in a 'native' way on derby.js

I simply don't want to fall back to ajax with server routes when all the rest is real time.


Solution

  • You can route the request onto the server via the model ( model.fetch() & model.subscribe() ). If it's just retrieving some data from the server, you are basically all set. Keep a reference to the model for when you need it (in app.ready callback as pointed out by switz).

    To use sockets directly or to extend the model (which uses sockets in the background) see https://groups.google.com/forum/?pli=1#!topic/derbyjs/60gouek7334