Show:

F2.AppHandlers Class

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

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.

isLocal (
  • url
)

Tests a URL to see if it's on the same domain (local) or not

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.

parse (
  • url
)

Parses URI

toAbsolute (
  • base
  • href
)

Abosolutizes a relative URL

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.


isLocal (
  • url
)

Defined in src\utils\uri.js:1

Tests a URL to see if it's on the same domain (local) or not

Parameters:

  • url URL to test

Returns:

Bool:

Whether the URL is local or not Derived from: https://github.com/jquery/jquery/blob/master/src/ajax.js


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!'); }
	                                    );

parse (
  • url
)

Defined in src\utils\uri.js:49

Parses URI

Parameters:

  • url The URL to parse

toAbsolute (
  • base
  • href
)

Defined in src\utils\uri.js:79

Abosolutizes a relative URL

Parameters:

  • base e.g., location.href
  • href URL to absolutize