is there any way for the binder to get data from the controller that is not in the view?

I haven't found a way for the binder to receive information directly from the controller without it being inserted somehow into the DOM like:
<script>var xxx = {{{extraData}}}</script>  or adding extra attributes to DOM nodes or concatenating stuff into the className of elements, like:
<input name="field1" value="{{field1}}" class="{{field1validation}}" /> 

I can add such information to the class attribute of the <input> boxes as shown above, which is not terribly bad.  However, for more extensive amounts of information, this is needlessly complicated and slow since accessing the DOM is never cheap.

Basically what I mean is that I would like to be able to read the very same first argument of ac.done(data) as the template processor gets it.

I realize that this might not be cheap since the template might have been processed in the server so providing such data, if large enough, might duplicate the amount of data transferred.  Perhaps a better solution would be to do something like:

ac.done(data, {binder:{data:extraData}});

So that the developer can explicitly say which data needs to be provided to the binder.

2 Replies

  • No. You cannot.

    Controller controls the data of the view, and only of the view.
    To share the data to the binder, the view must have that extra content that can be consumed by the binder.

    Note that binders are "only on the client side". Controllers can be server / client / common, views are rendered by controller (wherever the latter is executed), however binders are only {action}.js (no server / client / common).

    Having said that, your idea of ac.done(data, { binder: ... }) is indeed a good one.
    +1 from me :)

    Happy Hacking,
    Gaurav Vaish
  • Right, I know controllers can execute at either end so what I am asking is not trivial, however, Mojito could automate what I do tampering with the view. Mojito already adds plenty of with the difference that Mojito itself could add it automatically and the variable extraData could be some property within MojitProxy. Mojito could do more or less the same without troubling the template handler to process it and sparing me the need to json-stringify the data first.And it would look far less of a kludge.

Recent Posts

in Yahoo! Mojito