library ajax;
import 'dart:html';
import 'dart:async';
class Ajax {
static Ajax _instance;
StreamController _onLoadEndStreamController = new StreamController.broadcast();
/**
* Singleton Factory
*/
factory Ajax(){
return getInstance();
}
/**
* Ajax is Singleton so, the constructor is private
*/
Ajax._private(){
}
static Ajax getInstance(){
if(_instance == null){
_instance = new Ajax._private();
}
return _instance;
}
/**
* Return a request that always have one listen to forward globally
* Dispatches the event for the world. All the events that this class support have to be added here
*/
HttpRequest _createRequest(){
HttpRequest request = new HttpRequest();
request.onLoadEnd.listen(_onLoadEndHandler);
return request;
}
/**
* Dispatches the event for the world
*/
_onLoadEndHandler(event){
_onLoadEndStreamController.add(event);
}
/**
* Gets for the request and onLoadEnd Stream
*/
Stream<HttpRequestProgressEvent> get onLoadEnd => _onLoadEndStreamController.stream;
HttpRequest get request => _createRequest();
}