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
- F2.registerApps() method is called by the Container Developer and the following methods are run for each F2.AppConfig passed.
- 'appCreateRoot' (F2.Constants.AppHandlers.APP_CREATE_ROOT) handlers are fired in the order they were attached.
- 'appRenderBefore' (F2.Constants.AppHandlers.APP_RENDER_BEFORE) handlers are fired in the order they were attached.
- Each app's
manifestUrlis requested asynchronously; on success the following methods are fired. - 'appRender' (F2.Constants.AppHandlers.APP_RENDER) handlers are fired in the order they were attached.
- 'appRenderAfter' (F2.Constants.AppHandlers.APP_RENDER_AFTER) handlers are fired in the order they were attached.
App Removal
- F2.removeApp() with a specific F2.AppConfig/instanceId or F2.removeAllApps() method is called by the Container Developer and the following methods are run.
- 'appDestroyBefore' (F2.Constants.AppHandlers.APP_DESTROY_BEFORE) handlers are fired in the order they were attached.
- 'appDestroy' (F2.Constants.AppHandlers.APP_DESTROY) handlers are fired in the order they were attached.
- 'appDestroyAfter' (F2.Constants.AppHandlers.APP_DESTROY_AFTER) handlers are fired in the order they were attached.
Error Handling
- 'appScriptLoadFailed' (F2.Constants.AppHandlers.APP_SCRIPT_LOAD_FAILED) handlers are fired in the order they were attached.
src\appHandlers.js:151
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
(
|
Allows F2 to trigger specific events internally. |
| getToken ( ) | Allows Container Developer to retrieve a unique token which must be passed to
all |
isLocal
(
|
Tests a URL to see if it's on the same domain (local) or not |
off
(
|
Allows Container Developer to remove listener methods for specific events |
on
(
|
Allows Container Developer to easily tell all apps to render in a specific location. Only valid for eventType |
on
(
|
Allows Container Developer to add listener method that will be triggered when a specific event occurs. |
parse
(
|
Parses URI |
toAbsolute
(
|
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:
-
tokenStringThe token received from __f2GetToken.
-
eventKeyStringThe event to fire. The complete list of event keys is available in F2.Constants.AppHandlers.
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
Parameters:
-
urlURL to test
Returns:
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:
-
tokenStringThe token received from getToken.
-
eventKey{.namespace}StringThe 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:
-
tokenStringThe token received from getToken.
-
eventKey{.namespace}StringThe 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.
-
elementHTMLElementSpecific 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:
-
tokenStringThe token received from getToken.
-
eventKey{.namespace}StringThe 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.
-
listenerFunctionA 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
)
Parses URI
Parameters:
-
urlThe URL to parse
Returns:
string Source: https://gist.github.com/Yaffle/1088850 Tests: http://skew.org/uri/uri_tests.html
toAbsolute
(
-
base
-
href
)
Abosolutizes a relative URL
Parameters:
-
basee.g., location.href -
hrefURL to absolutize
Returns:
URL Source: https://gist.github.com/Yaffle/1088850 Tests: http://skew.org/uri/uri_tests.html