>
> becomes slower, there upto about 30 requests going backwards and
> forwards per "new form" view.
Ext.Direct will cache requests within x ms and lump them all together before
sending off to the server.
eg:
<script>
Ext.Direct.addProvider({
url: '/router/rpc', <-- see Router controller following.
type: 'remoting',
actions: {
UserPart : [ // <-- defining the API
{name: 'list', len: 1},
{name: 'create', len: 1},
{name: 'destroy', len: 1}
]
}
});
UserPart.list({order: 'ASC'}, onList);
UserPart.create({first: 'foo', last: 'bar'}, onCreate);
UserPart.destroy(1, onDestroy);;
// callbacks.
function onList(data, response) { };
function onCreate(data, response) { };
function onDestroy(data, response) { };
</script>
The merb-ext-direct gem is very small and comes with a controller mixin. it
will automatically create a public, ajax-only action named "rpc" in your
controller.
<code>
class Router < Merb::Controller
include Merb::ExtJS::RemotingProvider
end
</code>
Handling a request within the RemotingProvider mixin:
<code>
def handle_request(req)
req = XRequest.new(req)
begin
return part(Extlib::Inflection.constantize(req.controller) =>
req.action, :xrequest => req)
rescue XException => e
return XExceptionResponse.new(req, e).to_json
rescue StandardError => e
return XExceptionResponse.new(req, e).to_json
end
end
</code>
> To be able to use Merb as the backend
> and ExtJS as the frontend and have it all nicely integrated would be a
> big plus.
>
> Looking forward to seeing more.
>
> On Thu, Feb 5, 2009 at 8:45 PM, Matt Aimonetti <[email protected]>
> wrote:
> > That's really cool Chris, it looks like you found an interesting way to
> use
> > the parts.
> >
> > Keep on us posted,
> >
> > - Matt
> >
> > On Wed, Feb 4, 2009 at 11:22 PM, christocracy <[email protected]>
> > wrote:
> >>
> >> > eg:
> >> > <script>
> >> > Ext.onReady(function() {
> >> > UserPart.create({first : 'joma', last: 'cutchcutch'}, function
> >> > (data, response) {
> >> > alert('this is the callback');});
> >> >
> >> > });
> >> > </script>
> >>
> >> and UserPart#create would go something like this:
> >> <code>
> >> class UserPart < Merb::PartController
> >> def create
> >> req = params[:xrequest] # <-- XRequest instance provided
> >> automatically for you by merb-extjs-direct gem
> >> user = User.create(req.params)
> >> throw XException.new("Could not create user") if user.id.nil? #
> >> <-- throw an XException back to Ext.Direct on client.
> >> res = XResponse.new(req) # <-- Ext.Direct response class
> >> XResponse provided by merb-extjs-direct gem
> >> res.status = true
> >> res.message "Created new user"
> >> res.to_json
> >> end
> >> end
> >> </code>
> >>
> >
> >
> > >
> >
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"merb" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/merb?hl=en
-~----------~----~----~----~------~----~------~--~---