Multiple view instances

0 views
Skip to first unread message

Jrad

unread,
Jun 15, 2010, 4:28:21 AM6/15/10
to jquery-claypool
Dear Chris,
How can we create multiple instances of a view in the controller?

chris thatcher

unread,
Jun 15, 2010, 9:16:00 PM6/15/10
to jquery-...@googlegroups.com
Hey Jrad,
There are several basic patterns to multiple views with claypool.

Basically they fall into two patterns, the first being a direct call to render to a default or specified view.

//controller
event.m({
    template: 'some/template.tmpl',
    person: {
        name: 'chris thatcher'
    },
    results: [{
        title:'lorem',
        link:'http://pathtoit'
    },{
        title:'lorem',
        link:'http://pathtoit'
    }]
})

 Even when calling a view directly, the view can be attach to multiple dom nodes so the same rendering is applied to several places in the dom. 

$.invert([
...
{id:"#pagesView",  clazz:"Metasearch.Views.Pages", selector:".pagination" },
...
]);

now each node with the class='pagination' will be rendered with the pagesView update. This is typical of a pagination block for search results that is at both the top and bottom of the page. 

The second pattern is called broadcast and, in claypool, is implemented with filters, and it uses naming conventions to provide updates via 'filters', aka AOP.

//calls all similarly named views in serial to update
$.filters([
{
id : "#fooViewBroadcastFilter",
target : "MyApp.Views.Foo(.*)",
around : "(update)",
advice : function(invocation){
log = log||$.logger('MyApp.Filters');
log.debug('Intercepted call to update');
var model = invocation.arguments[0],
view = invocation.object;
this.update(model);
invocation.proceed();
}
}
]);
Let me know if thats not enough info.  PS, still working on normalizing form submissions so all form data is available through event.params();

Thatcher

On Tue, Jun 15, 2010 at 4:28 AM, Jrad <beh...@gmail.com> wrote:
Dear Chris,
How can we create multiple instances of a view in the controller?

--
You received this message because you are subscribed to the Google Groups "jquery-claypool" group.
To post to this group, send email to jquery-...@googlegroups.com.
To unsubscribe from this group, send email to jquery-claypo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jquery-claypool?hl=en.




--
Christopher Thatcher

chris thatcher

unread,
Jun 16, 2010, 8:46:51 AM6/16/10
to jquery-...@googlegroups.com
Hey I didnt do a great job on those examples, it was a little late and I was hurrying.  Heres a better break down:

1. directly calling views


event.m({
    template: 'some/template.tmpl',
    person: {
        name: 'chris thatcher'
    },
    results: [{
        title:'lorem',
        link:'http://pathtoit'
    },{
        title:'lorem',
        link:'http://pathtoit'
    }]
}).
render().//renders default view method 'update'
v('.mymethod').render().//renders default view method 'mymethod'
v('#otherView.update').render().//renders #otherView method 'update'

2. attaching view to multiple dom nodes

$.invert([
    {id:'#pagesView', clazz: 'MyApp.Views.Pagination', selector:'.pagination'}
])

recall views are normally associated with a single node with matching id, eg <div id='pages'> in this case we can have several <div class='pages'></div><div class='pages'></div> and they will all be rendered as part of the standard flow.

3. Broadcast

This just using some naming convention patterns to allow calling render() on one view to actually render many views.  So assuming I have a MyApp.Views.Foo I can broadcast to the 'MyApp.Views.FooBar' views with this

$.filters([{

    id: '#fooViewBroacastFilter',
    target: 'MyApp.Views.Foo(.+)',

    around: '(update)',
    advice: function(invocation){
        var model = invocation.arguments[0];
        this.update(model);
        invocation.proceed();
    }

}])


Hopes thats more clear than my first attempt.
--
Christopher Thatcher
Reply all
Reply to author
Forward
0 new messages