Yahoo! UI Library

poller  1.0.0

Yahoo! UI Library > poller > Poller
Search:
 
Filters

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 notify the client via Callbacks and Events when the resource has changed.

Constructor

Poller ( config )
Parameters:
config <Object> Configuration Object

Properties

_activeTx - protected Object

active IO transaction Object

_etag - protected String

Etag of the resource returned by the server, used to determine if the resource has changed.

_modifiedDate - protected String

Last-Modified date of the resource that the server returned, used to determine if the resource has changed.

_timer - protected Y.later

Timer object to schedule next request to server.

_txTime - protected Number

Time of the last request was sent.

Poller.ATTRS - static Object

Static property used to define the default attribute configuration of the component.

Poller.NAME - static String

The identity of the component.

Methods

_defCompleteHandler

protected void _defCompleteHandler ( txId , r , args )
Schedules the next transaction and calls the config's on.complete handler.
Parameters:
txId <Number> Y.io Transaction ID
r <Object> Y.io Response Object
args <MIXED> Arguments passed to handlers

_defModifiedHandler

protected void _defModifiedHandler ( txId , r , args )
Caches Etag and Last-Modified sent back from the server and calls the config's on.modified handler.
Parameters:
txId <Number> Y.io Transaction ID
r <Object> Y.io Response Object
args <MIXED> Arguments passed to handlers

_defStartHandler

protected void _defStartHandler ( txId , args )
Sets the txTime and calls the config's on.start handler.
Parameters:
txId <Number> Y.io Transaction ID
args <MIXED> Arguments passed to handlers

_defSuccessHandler

protected void _defSuccessHandler ( txId , r , args )
Chains to the modified callback and calls the config's on.success handler.
Parameters:
txId <Number> Y.io Transaction ID
r <Object> Y.io Response Object
args <MIXED> Arguments passed to handlers

destructor

protected void destructor ( )
Destruction of the component. Stops polling and cleans up.

initializer

protected void initializer ( config )
Construction of the component.
Parameters:
config <Object> Configuration Object

sendRequest

protected void sendRequest ( )
Sends the XHR request to the server at the given URI (resource). Method used internally to make the XHR requests.

start

void start ( )
Starts the polling task. A request will be sent to the server right at the time of calling this method; and continued by sending subsequent requests at the set interval. To stop or pause polling call the stop method.

stop

void stop ( )
Stops the polling task. Start can be called to resume polling.

Y.io.poll

static Poller Y.io.poll ( interval , uri , config )
Method for scheduling a XHR-polling task. Returns an instance of Poller
Parameters:
interval <Number> The time in milliseconds for which the component should send a request to the server.
uri <Object> qualified path to transaction resource.
config <Object> configuration object for the transaction(s); just like Y.io's config object, but with an on:modified callback/event.
Returns: Poller
an instance of Poller which has start/stop methods and a configurable interval

Events

intervalChange

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

io:modified

io:modified ( 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 to subscribe to. The subscriber could, for example, update the UI in response to this event, poller:modified.
Parameters:
txId <Number> Y.io Transaction ID
r <Object> Y.io Response Object
args <MIXED> Arguments passed to response handler

ioConfigChange

ioConfigChange ( event )
Fires when the value for the configuration attribute 'ioConfig' 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

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

uriChange

uriChange ( event )
Fires when the value for the configuration attribute 'uri' 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

Configuration Attributes

interval - Number

The time in milliseconds for which the component should send a request to the server.

ioConfig - writeonce Object

The configuration Y.io config.

polling - readonly Boolean

A read-only attribute the client can check to see if the component is actively polling the server.
Default Value: false

uri - writeonce String

The URI of the resource which to xhr-poll.


Copyright © 2009 Yahoo! Inc. All rights reserved.