Class: RequestScreen

RequestScreen


new RequestScreen()

Request screen abstract class to perform io operations on descendant screens.

Extends

Members


<static> GET :string

Holds value for method get.
Type:
  • string
Default Value:
  • 'get'

<static> POST :string

Holds value for method post.
Type:
  • string
Default Value:
  • 'post'

<static> X_REQUEST_URL_HEADER :string

Fallback http header to retrieve response request url.
Type:
  • string
Default Value:
  • 'X-Request-URL'

<protected, non-null> cache :Object

Holds the cached data.
Type:
  • Object
Inherited From:
Default Value:
  • null

<protected> cacheable :boolean

Holds whether class is cacheable.
Type:
  • boolean
Inherited From:
Overrides:
Default Value:
  • false

<protected, nullable> httpHeaders :Object

Holds default http headers to set on request.
Type:
  • Object
Default Value:
  • { 'X-PJAX': 'true', 'X-Requested-With': 'XMLHttpRequest' }

<protected, non-null> httpMethod :string

Holds default http method to perform the request.
Type:
  • string
Default Value:
  • RequestScreen.GET

<protected> id :string

Holds the screen id.
Type:
  • string
Inherited From:

<protected> request :XMLHttpRequest

Holds the XHR object responsible for the request.
Type:
  • XMLHttpRequest
Default Value:
  • null

<protected, non-null> timeout :number

Holds the request timeout in milliseconds.
Type:
  • number
Default Value:
  • 30000

<protected, nullable> title :string

Holds the screen title. Relevant when the page title should be upadated when screen is rendered.
Type:
  • string
Inherited From:
Default Value:
  • null

Methods


activate()

Fires when the screen is active. Allows a screen to perform any setup that requires its DOM to be visible. Lifecycle.
Inherited From:

addCache(content)

Adds content to the cache.
Parameters:
Name Type Description
content string Content to be cached.
Inherited From:

<protected> assertValidResponseStatusCode(status)

Asserts that response status code is valid.
Parameters:
Name Type Description
status number

beforeDeactivate()

Gives the Screen a chance to cancel the navigation and stop itself from being deactivated. Can be used, for example, if the screen has unsaved state. Lifecycle. Clean-up should not be preformed here, since the navigation may still be cancelled. Do clean-up in deactivate.
Inherited From:
Returns:
If returns true, the current screen is locked and the next nagivation interrupted.
Type
boolean

beforeUpdateHistoryPath()

Gives the Screen a chance format the path before history update.
Inherited From:
Overrides:
Returns:
Navigation path to use on history.
Type
string

beforeUpdateHistoryState()

Gives the Screen a chance format the state before history update.
Inherited From:
Overrides:
Returns:
History state to use on history.
Type
object

clearCache()

Clears the cache.
Inherited From:

deactivate()

Allows a screen to do any cleanup necessary after it has been deactivated, for example cancelling outstanding requests or stopping timers. Lifecycle.
Inherited From:

disposeInternal()

Dispose a screen, either after it is deactivated (in the case of a non-cacheable view) or when the App is itself disposed for whatever reason. Lifecycle.
Inherited From:

evaluateScripts(surfaces)

Allows a screen to evaluate scripts before the element is made visible. Lifecycle.
Parameters:
Name Type Description
surfaces object Map of surfaces to flip keyed by surface id.
Inherited From:
Returns:
This can return a promise, which will pause the navigation until it is resolved.
Type
CancellablePromise

evaluateStyles(surfaces)

Allows a screen to evaluate styles before the element is made visible. Lifecycle.
Parameters:
Name Type Description
surfaces object Map of surfaces to flip keyed by surface id.
Inherited From:
Returns:
This can return a promise, which will pause the navigation until it is resolved.
Type
CancellablePromise

flip(surfaces)

Allows a screen to perform any setup immediately before the element is made visible. Lifecycle.
Parameters:
Name Type Description
surfaces object Map of surfaces to flip keyed by surface id.
Inherited From:
Returns:
This can return a promise, which will pause the navigation until it is resolved.
Type
CancellablePromise

<protected> formatLoadPath(path)

Formats load path before invoking ajax call.
Parameters:
Name Type Description
path string
Returns:
Formatted path;
Type
string

<protected> getCache()

Gets the cached content.
Inherited From:
Returns:
Cached content.
Type
Object

getHttpHeaders()

Gets the http headers.
Returns:
Type
Object

getHttpMethod()

Gets the http method.
Returns:
Type
string

getId()

Gets the screen id.
Inherited From:
Returns:
Type
string

getRequest()

Gets the request object.
Returns:
Type
Object

getRequestPath()

Gets request path.
Returns:
Type
string

getSurfaceContent(surfaceId)

Returns the content for the given surface, or null if the surface isn't used by this screen. This will be called when a screen is initially constructed or, if a screen is non-cacheable, when navigated.
Parameters:
Name Type Description
surfaceId string The id of the surface DOM element.
Inherited From:
Returns:
This can return a string or node representing the content of the surface. If returns falsy values surface default content is restored.
Type
string | Element

getTimeout()

Gets the request timeout.
Returns:
Type
number

getTitle()

Gets the screen title.
Inherited From:
Returns:
Type
string

isCacheable()

Whether the class is cacheable.
Inherited From:
Returns:
Returns true when class is cacheable, false otherwise.
Type
boolean

isValidResponseStatusCode(statusCode)

Checks if response succeeded. Any status code 2xx or 3xx is considered valid.
Parameters:
Name Type Description
statusCode number

load( [path])

Returns all contents for the surfaces. This will pass the loaded content to Screen.load with all information you need to fulfill the surfaces. Lifecycle.
Parameters:
Name Type Argument Description
path string <optional>
The requested path.
Inherited From:
Overrides:
Returns:
This can return a string representing the contents of the surfaces or a promise, which will pause the navigation until it is resolved. This is useful for loading async content.
Type
CancellablePromise

maybeExtractResponseUrlFromRequest(request)

The following method tries to extract the response url value by checking the custom response header 'X-Request-URL' if proper value is not present in XMLHttpRequest. The value of responseURL will be the final URL obtained after any redirects. Internet Explorer, Edge and Safari <= 7 does not yet support the feature. For more information see: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseURL https://xhr.spec.whatwg.org/#the-responseurl-attribute
Parameters:
Name Type Description
request XMLHttpRequest
Returns:
Response url best match.
Type
string

setCacheable(cacheable)

Sets whether the class is cacheable.
Parameters:
Name Type Description
cacheable boolean
Inherited From:

setHttpHeaders( [httpHeaders])

Sets the http headers.
Parameters:
Name Type Argument Description
httpHeaders Object <optional>
<nullable>

setHttpMethod(httpMethod)

Sets the http method.
Parameters:
Name Type Description
httpMethod string

setId(id)

Sets the screen id.
Parameters:
Name Type Description
id string
Inherited From:

setRequest(request)

Sets the request object.
Parameters:
Name Type Argument Description
request Object <nullable>

setTimeout(timeout)

Sets the request timeout in milliseconds.
Parameters:
Name Type Description
timeout number

setTitle( [title])

Sets the screen title.
Parameters:
Name Type Argument Description
title string <optional>
<nullable>
Inherited From:

toString()

Inherited From:
Returns:
Type
string