Where a controller method gets called from
Several different places and the arguments a method receives depend entirely on which one called it.
This page is a map of those, not a re-explanation of each, most already have their own page.
Route lifecycle
Seven hooks, all optional, called automatically for whichever route is active. This is the full set:
(function (ctrl)
{
// fires after loading the required route data and sources
ctrl.load = function ()
{
}
// fires when data is received, before the client data is updated.
// return false to cancel further processing of the data object
ctrl.preDataUpdate = function (data)
{
}
// fires after the client data is updated
ctrl.postDataUpdate = function ()
{
}
// fires before the view is rendered/updated
ctrl.preRender = function ()
{
}
// fires after the view is rendered/updated
ctrl.postRender = function ()
{
}
// fires once the route has fully loaded
ctrl.postLoad = function ()
{
}
// fires when the current route is about to be unloaded, either because a new
// route was requested or the window itself is unloading.
// return false to cancel and keep the current route active
ctrl.unload = function (routeIndex, routePath, pageHide)
{
}
})($bindary.controller);
load and postLoad fire once, at the start and end of the route's lifetime.
unload fires once too, at the end and can cancel the navigation by returning
false. Its routeIndex/routePath refer to the
requested route, not the current one. Cancelling while pageHide is
true is unlikely to actually stop the window from closing, browsers don't
generally let script cancel that outright. Everything else,
preDataUpdate, postDataUpdate, preRender, postRender,
fires repeatedly over that lifetime, once per incoming update or render pass.
A route can point these at different method names instead, through controllerLoad,
controllerPreDataUpdate, controllerPostDataUpdate,
controllerPreRender, controllerPostRender, controllerPostLoad and
controllerUnload on the route definition, useful if one controller file serves more than one
route without its hooks clashing.
Per-element render hooks
b-pre-render and b-post-render are a different pair from the route-level ones
above, these are tied to one specific element, not the whole route and fire on every render pass for
that element. preRender receives the element's own templateItem plus a render
callback, returning false stops that element from rendering and shows a placeholder instead.
postRender receives just the templateItem, returning false hides
the element after it rendered.
ctrl.preRenderDate = (templateItem, render) =>
{
if (!someCondition)
return false; // don't render this element right now
};
Conditionals, filters, formatters
if/else-if methods receive the
templateItem and return a boolean. filter receives the
templateItem and the collection and returns the filtered version.
view-formatter and
data-formatter both receive
(templateItem, element, value) and return the transformed value.
DOM events
b-on-* attributes call a controller method directly in
response to a browser event, (templateItem, event).
Expressions
{{ methodName() }} inside an expression also resolves to a controller method, unless it's
inside a component that has one by that name instead, see
calling a controller or component method for the exact
resolution order.