Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controller doesn't wait the Model to finish loading the data before rendering. #44

Open
giuliandrimba opened this issue Jun 6, 2013 · 5 comments

Comments

@giuliandrimba
Copy link
Contributor

The default controller action implementation doesn't wait themodel to load the data before rendering the view

Eg:

index:()->
    if Model.all?
      @render "todo/index", Model.all()
    else
      @render "todo/index", null

I am still thinking about a better implementation for this, do you have any thoughts?

@arboleya
Copy link
Member

arboleya commented Jun 6, 2013

Have you checked this?
https://github.com/serpentem/theoricus/blob/master/www/src/theoricus/mvc/controller.coffee#L49-L56

###
  Renders to some view

  @param [String] path  Path to view on the app tree
  @param [String] data  data to be rendered on the template
  ###
  render:( path, data )->
    @the.factory.view path, (view)=>

      @process.view = view

      view.process = @process
      view.after_in = @after_render

      if data instanceof Fetcher
        if data.loaded
          view._render data.records
        else
          data.onload = ( records ) =>
            view._render records
      else
        view._render data

@hems
Copy link
Member

hems commented Jun 7, 2013

I agree before the data is loaded, another method should be called ( perhaps, before_receive_data ? ) so the view can have an action before the template's data is received.

Some times you want your view to be rendered before the data is loaded in order to add a loader to the DOM.

Actually now i remember @arboleya saying something about solving this "gap" somewhere else in the framework.

Still i do think we might benefit from calling "before_receive_data" ( or something like that ) in the view before calling render.

This is actually a sensible subject, since some applications have loaders following the mouse, therefore not destroying the current view until the data is loaded.

Other's actually needs to destroy the view instantly and render the loader into the "#container" div which will actually render the new view after loading the data.

@arboleya
Copy link
Member

arboleya commented Jun 7, 2013

This awkward behavior introduced by the Fetcher class was something I need long time ago when implementing the first draft of the Model class (is basically what remains until now and it's poorly tested).

At that time, the Controller's actions MUST to always return a view instance. As the Model introduced some async back and forth, the render method has faced some problems returning the View instance when the data wasn't loaded. This is the gap.

Currently it seems that this can be totally improved since the Controller's actions do not have to return a view instance anymore. Need to be tested and confirmed before any further actions.

@hems
Copy link
Member

hems commented Jun 7, 2013

my bad, i didnt know it didnt need to return a view on v2.

Anyway i still think having either a loader assciated with a cotainer or a view being created and notified about the fact the data is being loaded ( therefore the render chain will br called soon ) can be very useful!

peace

@arboleya
Copy link
Member

arboleya commented Jun 7, 2013

The whole loading process, not only of model data but also assets etc, must to be demystified and designed to work in a transparent way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants