Show:

F2.AppHandlers Class

The new AppHandlers functionality provides Container Developers a higher level of control over configuring app rendering and interaction.

The addition of F2.AppHandlers replaces the previous F2.ContainerConfig properties beforeAppRender, appRender, and afterAppRender. These methods were deprecated—but not removed—in version 1.2. They will be permanently removed in a future version of F2.

Starting with F2 version 1.2, AppHandlers is the preferred method for Container Developers to manage app layout.

Order of Execution

App Rendering

  1. F2.registerApps() method is called by the Container Developer and the following methods are run for each F2.AppConfig passed.
  2. 'appCreateRoot' (F2.Constants.AppHandlers.APP_CREATE_ROOT) handlers are fired in the order they were attached.
  3. 'appRenderBefore' (F2.Constants.AppHandlers.APP_RENDER_BEFORE) handlers are fired in the order they were attached.
  4. Each app's manifestUrl is requested asynchronously; on success the following methods are fired.
  5. 'appRender' (F2.Constants.AppHandlers.APP_RENDER) handlers are fired in the order they were attached.
  6. 'appRenderAfter' (F2.Constants.AppHandlers.APP_RENDER_AFTER) handlers are fired in the order they were attached.

App Removal

  1. F2.removeApp() with a specific F2.AppConfig/instanceId or F2.removeAllApps() method is called by the Container Developer and the following methods are run.
  2. 'appDestroyBefore' (F2.Constants.AppHandlers.APP_DESTROY_BEFORE) handlers are fired in the order they were attached.
  3. 'appDestroy' (F2.Constants.AppHandlers.APP_DESTROY) handlers are fired in the order they were attached.
  4. 'appDestroyAfter' (F2.Constants.AppHandlers.APP_DESTROY_AFTER) handlers are fired in the order they were attached.

Error Handling

  1. 'appScriptLoadFailed' (F2.Constants.AppHandlers.APP_SCRIPT_LOAD_FAILED) handlers are fired in the order they were attached.

Methods

Name Description
__f2GetToken ( ) private

Allows F2 to get a token internally. Token is required to call __trigger. This function will self destruct to eliminate other sources from using the __trigger and additional internal methods.

__trigger (
  • token
  • eventKey
)
private

Allows F2 to trigger specific events internally.

getToken ( )

Allows Container Developer to retrieve a unique token which must be passed to all on and off methods. This function will self destruct and can only be called one time. Container Developers must store the return value inside of a closure.

off (
  • token
  • eventKey{.namespace}
)

Allows Container Developer to remove listener methods for specific events

on (
  • token
  • eventKey{.namespace}
  • element
)

Allows Container Developer to easily tell all apps to render in a specific location. Only valid for eventType appRender.

on (
  • token
  • eventKey{.namespace}
  • listener
)

Allows Container Developer to add listener method that will be triggered when a specific event occurs.

Methods

__f2GetToken ( ) private

Allows F2 to get a token internally. Token is required to call __trigger. This function will self destruct to eliminate other sources from using the __trigger and additional internal methods.


__trigger (
  • token
  • eventKey
) private chainable

Allows F2 to trigger specific events internally.

Parameters:


getToken ( )

Allows Container Developer to retrieve a unique token which must be passed to all on and off methods. This function will self destruct and can only be called one time. Container Developers must store the return value inside of a closure.


off (
  • token
  • eventKey{.namespace}
) chainable

Allows Container Developer to remove listener methods for specific events

Parameters:

  • token String

    The token received from getToken.

  • eventKey{.namespace} String

    The event key used to determine which event to attach the listener to. If no namespace is provided all listeners for the specified event type will be removed. Complete list available in F2.Constants.AppHandlers.

Example:

var _token = F2.AppHandlers.getToken();
F2.AppHandlers.off(_token,'appRenderBefore');

on (
  • token
  • eventKey{.namespace}
  • element
) chainable

Allows Container Developer to easily tell all apps to render in a specific location. Only valid for eventType appRender.

Parameters:

  • token String

    The token received from getToken.

  • eventKey{.namespace} String

    The event key used to determine which event to attach the listener to. The namespace is useful for removal purposes. At this time it does not affect when an event is fired. Complete list of event keys available in F2.Constants.AppHandlers.

  • element HTMLElement

    Specific DOM element to which app gets appended.

Example:

var _token = F2.AppHandlers.getToken();
F2.AppHandlers.on(
    _token,
    'appRender',
    document.getElementById('my_app')
);

Or:

F2.AppHandlers.on(
    _token,
    'appRender.myNamespace',
    document.getElementById('my_app')
);

on (
  • token
  • eventKey{.namespace}
  • listener
) chainable

Allows Container Developer to add listener method that will be triggered when a specific event occurs.

Parameters:

  • token String

    The token received from getToken.

  • eventKey{.namespace} String

    The event key used to determine which event to attach the listener to. The namespace is useful for removal purposes. At this time it does not affect when an event is fired. Complete list of event keys available in F2.Constants.AppHandlers.

  • listener Function

    A function that will be triggered when a specific event occurs. For detailed argument definition refer to F2.Constants.AppHandlers.

Example:

var _token = F2.AppHandlers.getToken();
F2.AppHandlers.on(
    _token,
    'appRenderBefore'
    function() { F2.log('before app rendered!'); }
);

Or:

F2.AppHandlers.on(
    _token,
    'appRenderBefore.myNamespace',
    function() { F2.log('before app rendered!'); }
);