Class Poller
- extends Base
Create a polling task to continually check the server at the specified interval for updates of a resource at a URI.
The poller will use conditional GET requests and notifiy the client via Events when the resource has changed.
Constructor
Poller
(
config
)
- Parameters:
-
config
<Object>
Configuration Object
Properties
_blurHandle
- protected Event.Handle
Event handle referencing the binding to the window's blur event.
_etag
- protected String
Etag of the resource returned by the server, used to determine if the resource has changed.
_focusHandle
- protected Event.Handle
Event handle referencing the binding to the window's focus event.
Last-Modified date of the resource that the server returned, used to determine if the resource has changed.
_paused
- protected Y.later
Reference to the timer object which is waiting to resume from a pause request.
_poller
- protected Y.later
Reference to the timer object that's polling the server.
Static property used to define the default attribute configuration of
the component.
The identity of the component.
Properties inherited from Base:
Methods
protected
void
_afterHeadersChange
(
e
)
Invalidate the cached etag and modifiedDate used to determine if the resource has been changed.
Changing the HTTP headers can effect the response returned by the server.
Changing this attributed is treated like the changing the url attribute.
- Parameters:
-
e
<Event>
headersChange custom event
- Returns:
void
protected
void
_afterIntervalChange
(
e
)
If the polling task is active, it will be stopped then started to use the new interval.
- Parameters:
-
e
<Event>
intervalChange custom event
- Returns:
void
protected
void
_afterPauseInactiveChange
(
e
)
Enable/disable the pausing/resuming of the polling task when the window has become inactive/active.
- Parameters:
-
e
<Event>
pauseInactiveChange custom event
- Returns:
void
protected
void
_afterUrlChange
(
e
)
Invalidate the cached etag and modifiedDate used to determine if the resource has been changed.
If the polling task is active then send a request to the server right away.
- Parameters:
-
e
<Event>
urlChange custom event
- Returns:
void
protected
void
_clearPause
(
)
Utility method used to clear a pause timer that has been set.
protected
void
_disablePauseInactive
(
)
Detacheds the event handles from the window's focus and blur events.
Preventing the polling to pause when the window is inactive, polling will continue until stop or pause is called.
protected
void
_enablePauseInactive
(
)
Attaches the event handles to the focus and blur events on the window.
Provides a way to automatically pause polling when the browser window is inactive,
and starts the polling process right when the windows becomes active again.
protected
void
_handleBlur
(
e
)
Handles the window losing focus, blur.
Checks that the component is activly polling (stop hasn't been called), and pauses the polling task.
- Parameters:
-
e
<Object>
- Returns:
void
protected
void
_handleFocus
(
e
)
Handles the window coming into focus.
Checks that the component is activly polling (stop hasn't been called), and resumes the polling task.
- Parameters:
-
e
<Event>
Window focus event
- Returns:
void
protected
void
_handleModified
(
txId
,
r
,
args
)
Handles the response from a successful XHR request (2xx response status).
The resource has changed on the server if this method has been called.
Fires the poller:modified event.
- Parameters:
-
txId
<Number>
Y.io Transaction ID
-
r
<Object>
Y.io Response Object
-
args
<MIXED>
Arguments passed to response handler
- Returns:
void
protected
void
_handleResponse
(
txId
,
r
,
args
)
Handles the response from a completed XHR request.
Fires the poller:response event.
- Parameters:
-
txId
<Number>
Y.io Transaction ID
-
r
<Object>
Y.io Response Object
-
args
<MIXED>
Arguments passed to response handler
- Returns:
void
protected
void
_startPolling
(
)
Protected method that actually starts the polling task.
Calling this method will send a request to the server, fire the poller:start event, and create the interval task.
protected
void
_stopPolling
(
)
Protected method that actually stops the polling task.
Calling this method will stop the poller and fire the poller:stop event.
protected
void
destructor
(
)
Deconstruction of the component. Stops polling and removes event internal listeners.
protected
void
initializer
(
config
)
Construction of the component linking up and publishing event during initialization.
- Parameters:
-
config
<Object>
Configuration Ojbect
- Returns:
void
void
pause
(
duration
)
Pauses the polling task for a duration.
This method first calls stop, which will fire the poller:stop event;
which will also clear out a waiting pause to resume.
- Parameters:
-
duration
<Number>
milliseconds until resuming
- Returns:
void
Chainable: This method is chainable.
void
sendRequest
(
)
Sends the XHR request to the server at the given URL (resource).
This is method is call at the set interval while polling.
Calling this method will fire the poller:request event.
- Returns:
void
Chainable: This method is chainable.
void
start
(
)
Starts the polling task, the poller:start event is fired as a result of calling this method.
A request will be sent to the server right at the time of calling this method;
continued by sending subsequent requests at the set interval.
If the pause method has been called, calling start will clear the pause.
- Returns:
void
Chainable: This method is chainable.
void
stop
(
)
Stops the polling task, the poller:stop event is fired.
If the paused method has been called, calling start will clear the pause.
- Returns:
void
Chainable: This method is chainable.
Methods inherited from Base:
_defDestroyFn,
_defInitFn,
_getClasses,
after,
destroy,
fire,
init,
publish,
subscribe,
toString,
unsubscribe,
unsubscribeAll
Events
headersChange
(
event
)
Fires when the value for the configuration attribute 'headers' is changed. You can listen for the event using the
on method if you wish to be notified before the attribute's value has changed, or using the
after method if you wish to be notified after the attribute's value has changed.
- Parameters:
-
event
<Event.Facade>
An Event Facade object with the following attribute specific properties added: - prevVal
- The value of the attribute, prior to it being set
- newVal
- The value the attribute is to be set to
- attrName
- The name of the attribute being set
- subAttrName
- If setting a property within the attribute's value, the name of the sub-attribute property being set
intervalChange
(
event
)
Fires when the value for the configuration attribute 'interval' is changed. You can listen for the event using the
on method if you wish to be notified before the attribute's value has changed, or using the
after method if you wish to be notified after the attribute's value has changed.
- Parameters:
-
event
<Event.Facade>
An Event Facade object with the following attribute specific properties added: - prevVal
- The value of the attribute, prior to it being set
- newVal
- The value the attribute is to be set to
- attrName
- The name of the attribute being set
- subAttrName
- If setting a property within the attribute's value, the name of the sub-attribute property being set
modified
(
e
,
txId
,
r
,
args
)
Signals that the resource the component is pulling the server for has been modified.
This is the interesting event for the client ot subscribe to.
The subscriber could, for example, update the UI in response to this event, poller:modified.
- Parameters:
-
e
<Event.Facade>
Event Facade
-
txId
<Number>
Y.io Transaction ID
-
r
<Object>
Y.io Response Object
-
args
<MIXED>
Arguments passed to response handler
pauseInactiveChange
(
event
)
Fires when the value for the configuration attribute 'pauseInactive' is changed. You can listen for the event using the
on method if you wish to be notified before the attribute's value has changed, or using the
after method if you wish to be notified after the attribute's value has changed.
- Parameters:
-
event
<Event.Facade>
An Event Facade object with the following attribute specific properties added: - prevVal
- The value of the attribute, prior to it being set
- newVal
- The value the attribute is to be set to
- attrName
- The name of the attribute being set
- subAttrName
- If setting a property within the attribute's value, the name of the sub-attribute property being set
pollingChange
(
event
)
Fires when the value for the configuration attribute 'polling' is changed. You can listen for the event using the
on method if you wish to be notified before the attribute's value has changed, or using the
after method if you wish to be notified after the attribute's value has changed.
- Parameters:
-
event
<Event.Facade>
An Event Facade object with the following attribute specific properties added: - prevVal
- The value of the attribute, prior to it being set
- newVal
- The value the attribute is to be set to
- attrName
- The name of the attribute being set
- subAttrName
- If setting a property within the attribute's value, the name of the sub-attribute property being set
queryParamsChange
(
event
)
Fires when the value for the configuration attribute 'queryParams' is changed. You can listen for the event using the
on method if you wish to be notified before the attribute's value has changed, or using the
after method if you wish to be notified after the attribute's value has changed.
- Parameters:
-
event
<Event.Facade>
An Event Facade object with the following attribute specific properties added: - prevVal
- The value of the attribute, prior to it being set
- newVal
- The value the attribute is to be set to
- attrName
- The name of the attribute being set
- subAttrName
- If setting a property within the attribute's value, the name of the sub-attribute property being set
request
(
e
,
tx
)
Signals that the component has sent a XHR request to the Server.
The request object is passed to subscribers of the event, poller:request.
- Parameters:
-
e
<Event.Facade>
Event Facade
-
tx
<Object>
Y.io Request Object
response
(
e
,
txId
,
r
,
args
)
Signals that the component has received a response (io:complete) for the server, poller:response.
- Parameters:
-
e
<Event.Facade>
Event Facade
-
txId
<Number>
Y.io Transaction ID
-
r
<Object>
Y.io Response Object
-
args
<MIXED>
Arguments passed to response handler
start
(
e
)
Signals that polling has started, poller:start.
- Parameters:
-
e
<Event.Facade>
Event Facade
stop
(
e
)
Signals that polling has stopped, poller:stop.
- Parameters:
-
e
<Event.Facade>
Event Facade
timeoutChange
(
event
)
Fires when the value for the configuration attribute 'timeout' is changed. You can listen for the event using the
on method if you wish to be notified before the attribute's value has changed, or using the
after method if you wish to be notified after the attribute's value has changed.
- Parameters:
-
event
<Event.Facade>
An Event Facade object with the following attribute specific properties added: - prevVal
- The value of the attribute, prior to it being set
- newVal
- The value the attribute is to be set to
- attrName
- The name of the attribute being set
- subAttrName
- If setting a property within the attribute's value, the name of the sub-attribute property being set
urlChange
(
event
)
Fires when the value for the configuration attribute 'url' is changed. You can listen for the event using the
on method if you wish to be notified before the attribute's value has changed, or using the
after method if you wish to be notified after the attribute's value has changed.
- Parameters:
-
event
<Event.Facade>
An Event Facade object with the following attribute specific properties added: - prevVal
- The value of the attribute, prior to it being set
- newVal
- The value the attribute is to be set to
- attrName
- The name of the attribute being set
- subAttrName
- If setting a property within the attribute's value, the name of the sub-attribute property being set
Events inherited from Base:
Configuration Attributes
An Object containing the key : value pairs for any HTTP headers to be send with requests.
Default Value: null
The time in milliseconds for which the component should send a request to the server.
Default Value: 10000
Choice for the polling to be paused if the browser window loses focus, becoming an inactive window.
Default Value: false
polling
- readonly Boolean
A read-only attribute the client can check to see if the component is activly polling the server.
Default Value: false
A set of name=value pairs to be appened to the URL requests will be sent to.
Default Value: null
The time in milliseconds which the XHR request should abort if no response is received.
Default Value: 5000
url
- String
The URL of the resource which the component will check for modifications.
Default Value: null
Configuration attributes inherited from Base: