All yields get cleared when I try to render something into a specific yield

72 views
Skip to first unread message

Lauri Fjällström

unread,
Nov 8, 2012, 3:50:15 AM11/8/12
to batm...@googlegroups.com
I have this problem with multiple data-yields. When I render something into specific data-yield, all the other yields get cleared. Here is how my code looks something like:

window.MyApp = class Test extends Batman.App
 
@resources 'things'


class Thing extends Batman.Model
 
@encode 'id', 'name'


class ThingsController extends Batman.Controller
  things
: null
  thing
: null
  index
: ->
   
@set 'things', MyApp.Thing.get('all')
  show
: (params) ->
   
@set 'thing', MyApp.Thing.find id, (err) ->
     
throw err if err
   
@render source: 'things/details', into: 'thing-details'


views
/things/index.html:
<div>Things</div>
<div data-foreach-thing="things">
  <a data-bind="thing.name" data-route="routes.things[thing]"></
a>
</div>
<div data-yield="thing-details"></
div>


views
/things/detials.html:
<div data-bind="thing.name"></div>

I want to have this list of things. When I click a thing in the list I want its details to appear in an area next to the list. But what actually happens is that the main yield (inside which the yield thing-details is) gets cleared as well. So the list of things disappears and nothing gets displayed as the yield was inside the cleared area.

So the questions is, what am I doing wrong? Or did I misunderstood something how the yields should work?

Thanks,
Lauri

Jeff Berg

unread,
Nov 8, 2012, 11:55:03 AM11/8/12
to batm...@googlegroups.com
Lauri,

I think this is the right behavior, when you browse to a new page it should be clearing out the content out of all the unused yields.

To get around this use data-event-click instead of data-route

Jeff
--
Jeff Berg
Owner/Developer
Ministry Centered Technologies
=================================
REVOLUTIONIZE the way you plan your SERVICES at planningcenteronline.com
REVOLUTIONIZE the way you plan your EVENTS at smartevents.com

Lauri Fjällström

unread,
Nov 9, 2012, 1:46:22 AM11/9/12
to batm...@googlegroups.com
Thanks Jeff,

Why I want to use routes instead of handling the click myself is that I want the hash in the url to change so that users could add bookmarks to individual things. But I also realized that controllers don't support this kind of cascading (loading list of things before showing an individual thing). So I guess I need to rethink the design a bit.

Lauri

ad...@amcoonline.net

unread,
Dec 5, 2012, 2:12:07 PM12/5/12
to batm...@googlegroups.com
Lauri-

I'm dealing with a similar situation. Have you come up with a solution to this problem? Right now I'm trying creating and calling render helpers for other yields but that's annoying to deal with.

Lauri Fjällström

unread,
Dec 6, 2012, 3:22:13 AM12/6/12
to batm...@googlegroups.com
Hi,

I have created my own controller class that has an option to not clear all yields. The implementation is hacky and I believe there is a great chance that it will break some day when Batman gets updated. The code is like:

class My.Controller extends Batman.Controller
  clearAllYields: false

  _empty: ->

  dispatch: ->
    if not @clearAllYields
      cycleAll = Batman.DOM.Yield.cycleAll
      clearAllStale = Batman.DOM.Yield.clearAllStale
      Batman.DOM.Yield.cycleAll = @_empty
      Batman.DOM.Yield.clearAllStale = @_empty
    ret = super
    if not @clearAllYields
      Batman.DOM.Yield.cycleAll = cycleAll
      Batman.DOM.Yield.clearAllStale = clearAllStale
    ret

Using this implementation you need to keep in mind that you have to keep all yields in sync by yourself. For example in my case I have routes like /foos/42/bars/42/baz/42. If I go to /foos/42 a layout that has nested yield for bars are rendered. There are no problems when user first goes to foos and then to bars. But if one enter directly route /foos/42/bars/42 (by bookmarking or something) I need to make sure that all the higher level layouts will be rendered also. This kind of sucks and I hope I have time some day to write a controller class that supports this without dirty hacks. I have gone through all the trouble because our app really benefits from this.

Cheers,
Lauri
Reply all
Reply to author
Forward
0 new messages