Codementor Events

Chaining controller methods in Titanium Alloy

Published Jun 05, 2019
Chaining controller methods in Titanium Alloy

A nice feature of Titanium and Alloy is the ability to create controllers and be reactive to triggers OR call methods without creating a pointer.

So assuming we want to open a modal settings view and react to the settings being saved, BEFORE closing the view, we might typically write:

settings.getView().open({modal:true});
settings.on("saved", function(){
  // do stuff here
  settings = null;  
});

Which is fine but it’s a lot of code.

With Alloy, you can chain methods and do ALL this without ever creating the pointer variable.

  // do stuff here
}).getView().open({modal: true});

So basically we’ve achieved the same thing in a few lines of code — no pointer created, no potential memory leak issues!

Discover and read more posts from Jason Kneen
get started
post commentsBe the first to share your opinion
Show more replies