Created
January 31, 2015 22:37
-
-
Save nanuclickity/8e594cce912ef7d2a705 to your computer and use it in GitHub Desktop.
Automate view loading in layout regions on render
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define ['marionette', 'radio'], (Marionette, Radio)-> | |
class AutoLayout extends Marionette.Behavior | |
defaults: | |
regionViews: {} | |
regionViewsOptions: {} | |
events: | |
loadStart: 'loader:start' | |
loadStop: 'loader:stop' | |
onRender: -> | |
rViews = _.result @options.regionViews | |
unless _.isObject(rViews) and _.keys(rViews).length | |
return throw "Invalid regionViews" | |
_(rViews).each @attachView | |
attachView: (rURL, rName)-> | |
options = _.result(@options.regionViewsOptions)[rName] | |
region = @view.getRegion rName | |
evtStart = @options.events.loadStart | |
evtStop = @options.events.loadStop | |
@view.trigger evtStart, rURL, region | |
requirejs [rURL], (View)=> | |
view = new View(options) | |
region.show view | |
@view.trigger evtStop, view, region | |
window.Behaviors.AutoLayout = AutoLayout | |
return AutoLayout |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment