]> git.wh0rd.org - tt-rss.git/blame - lib/dojo/_base/Deferred.js
add dijit/dojo stuff; initial ui mockup
[tt-rss.git] / lib / dojo / _base / Deferred.js
CommitLineData
2f01fe57
AD
1/*
2 Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3 Available via Academic Free License >= 2.1 OR the modified BSD license.
4 see: http://dojotoolkit.org/license for details
5*/
6
7
8if(!dojo._hasResource["dojo._base.Deferred"]){
9dojo._hasResource["dojo._base.Deferred"]=true;
10dojo.provide("dojo._base.Deferred");
11dojo.require("dojo._base.lang");
12(function(){
13var _1=function(){
14};
15var _2=Object.freeze||function(){
16};
17dojo.Deferred=function(_3){
18var _4,_5,_6,_7,_8;
19var _9=this.promise={};
20function _a(_b){
21if(_5){
22throw new Error("This deferred has already been resolved");
23}
24_4=_b;
25_5=true;
26_c();
27};
28function _c(){
29var _d;
30while(!_d&&_8){
31var _e=_8;
32_8=_8.next;
33if(_d=(_e.progress==_1)){
34_5=false;
35}
36var _f=(_6?_e.error:_e.resolved);
37if(_f){
38try{
39var _10=_f(_4);
40if(_10&&typeof _10.then==="function"){
41_10.then(dojo.hitch(_e.deferred,"resolve"),dojo.hitch(_e.deferred,"reject"));
42continue;
43}
44var _11=_d&&_10===undefined;
45_e.deferred[_11&&_6?"reject":"resolve"](_11?_4:_10);
46}
47catch(e){
48_e.deferred.reject(e);
49}
50}else{
51if(_6){
52_e.deferred.reject(_4);
53}else{
54_e.deferred.resolve(_4);
55}
56}
57}
58};
59this.resolve=this.callback=function(_12){
60this.fired=0;
61this.results=[_12,null];
62_a(_12);
63};
64this.reject=this.errback=function(_13){
65_6=true;
66this.fired=1;
67_a(_13);
68this.results=[null,_13];
69if(!_13||_13.log!==false){
70(dojo.config.deferredOnError||function(x){
71console.error(x);
72})(_13);
73}
74};
75this.progress=function(_14){
76var _15=_8;
77while(_15){
78var _16=_15.progress;
79_16&&_16(_14);
80_15=_15.next;
81}
82};
83this.addCallbacks=function(_17,_18){
84this.then(_17,_18,_1);
85return this;
86};
87this.then=_9.then=function(_19,_1a,_1b){
88var _1c=_1b==_1?this:new dojo.Deferred(_9.cancel);
89var _1d={resolved:_19,error:_1a,progress:_1b,deferred:_1c};
90if(_8){
91_7=_7.next=_1d;
92}else{
93_8=_7=_1d;
94}
95if(_5){
96_c();
97}
98return _1c.promise;
99};
100var _1e=this;
101this.cancel=_9.cancel=function(){
102if(!_5){
103var _1f=_3&&_3(_1e);
104if(!_5){
105if(!(_1f instanceof Error)){
106_1f=new Error(_1f);
107}
108_1f.log=false;
109_1e.reject(_1f);
110}
111}
112};
113_2(_9);
114};
115dojo.extend(dojo.Deferred,{addCallback:function(_20){
116return this.addCallbacks(dojo.hitch.apply(dojo,arguments));
117},addErrback:function(_21){
118return this.addCallbacks(null,dojo.hitch.apply(dojo,arguments));
119},addBoth:function(_22){
120var _23=dojo.hitch.apply(dojo,arguments);
121return this.addCallbacks(_23,_23);
122},fired:-1});
123})();
124dojo.when=function(_24,_25,_26,_27){
125if(_24&&typeof _24.then==="function"){
126return _24.then(_25,_26,_27);
127}
128return _25(_24);
129};
130}