diff --git a/README.md b/README.md index b20390c0e..e33fb619f 100755 --- a/README.md +++ b/README.md @@ -98,6 +98,7 @@ List of Definitions * [jQuery](http://jquery.com/) (from TypeScript samples) * [jQuery Mobile](http://jquerymobile.com) (by [Boris Yankov](https://github.com/borisyankov)) * [jQuery UI](http://jqueryui.com/) (by [Boris Yankov](https://github.com/borisyankov)) +* [jQuery.Address](https://github.com/asual/jquery-address) (by [Martin Duparc](https://github.com/martinduparc/)) * [jQuery.areYouSure](https://github.com/codedance/jquery.AreYouSure) (by [Jon Egerton](https://github.com/jonegerton)) * [jQuery.autosize](http://www.jacklmoore.com/autosize/) (by [Jack Moore](http://www.jacklmoore.com/)) * [jQuery.BBQ](http://benalman.com/projects/jquery-bbq-plugin/) (by [Adam R. Smith](https://github.com/sunetos)) diff --git a/angularjs/angular.d.ts b/angularjs/angular.d.ts index 6da5dbf23..d0b24fda3 100755 --- a/angularjs/angular.d.ts +++ b/angularjs/angular.d.ts @@ -562,6 +562,7 @@ declare module ng { interface IHttpProvider extends IServiceProvider { defaults: IRequestConfig; + interceptors: any[]; responseInterceptors: any[]; } diff --git a/jquery.address/jquery.address.d.ts b/jquery.address/jquery.address.d.ts new file mode 100644 index 000000000..a89021583 --- /dev/null +++ b/jquery.address/jquery.address.d.ts @@ -0,0 +1,24 @@ +/// + +// Type definitions for jQuery.Address 1.5 +// Project: https://github.com/asual/jquery-address +// Definitions by: Martin Duparc <@martinduparc> +// Definitions: https://github.com/borisyankov/DefinitelyTyped/ + +interface JQueryAddressStatic { + (); + change(callback: any): void; + value(url: any): void; +} + +interface JQueryAddress { + (): JQuery; +} + +interface JQueryStatic { + address: JQueryAddressStatic; +} + +interface JQuery { + address: JQueryAddress; +} diff --git a/jsdeferred/jsdeferred-tests.ts b/jsdeferred/jsdeferred-tests.ts index 47fbf1a30..57ddfcc52 100644 --- a/jsdeferred/jsdeferred-tests.ts +++ b/jsdeferred/jsdeferred-tests.ts @@ -1,86 +1,135 @@ -/// /// declare function alert(a: any): void; -declare function log(a: any): void; -interface DeferredizedJQueryStatic extends JQueryStatic { - //get (url: string, data?: any, success?: any, dataType?: any): Deferred; -} -declare var $: DeferredizedJQueryStatic; - -interface http { +interface IHttp { get (url: string): Deferred; } +var http: IHttp; -/***** jsDoc case *****/ +Deferred.define(); -// constructor -(() => { - var d1 = new Deferred(); - var d2 = Deferred(); -})(); +next(function () { + alert("Hello!"); + return wait(5); +}). +next(function () { + alert("World!"); +}); -// define -(() => { - Deferred.define(); - $.get("/hoge").next(function (data) { - alert(data); +Deferred.next(function () { + alert("Hello!"); + return Deferred.wait(5); +}). +next(function () { + alert("World!"); +}); + +// http.get is assumed to be a function that takes a URI as an argument and returns a Deferred instance +var results = []; +next(function () { + return http.get("/foo.json").next(function (data) { + results.push(data); + }); +}). +next(function () { + return http.get("/baz.json").next(function (data) { + results.push(data); + }); +}). +next(function () { + return http.get("/baz.json").next(function (data) { + results.push(data); + }); +}). +next(function () { + alert(results); +}); + +var wants = ["/foo.json", "/bar.json", "/baz.json"]; +var results = []; +loop(wants.length, function (i) { + return http.get(wants[i]).next(function (data) { + results.push(data); + }); +}). +next(function () { + alert(results); +}); + +parallel([ + http.get("/foo.json"), + http.get("/bar.json"), + http.get("/baz.json") +]). +next(function (results) { + alert(results); +}); + +next(function () { + // something 1 +}). +next(function () { + // asynchronous process + throw "error!"; +}). +next(function () { + // something 2 (not executed as an error occurs in the previous process) +}); + +next(function () { + // something 1 +}). +next(function () { + // asynchronous process + throw "error!"; +}). +next(function () { + // something 2 (not executed as an error occurs in the previous process) +}). +error(function (e) { + alert(e); +}); + +next(function () { + // something 1 +}). +next(function () { + // asynchronous process + throw "error!"; +}). +error(function (e) { + alert(e); +}). +next(function () { + // something 2 (executed since the exception would already be handled) +}). +error(function (e) { + alert(e); +}); + +next(function () { + alert("Hello!"); + return wait(5); +}). +next(function () { + alert("World!"); +}); + +next(function () { + alert(1); + return next(function () { + alert(2); }). - parallel([$.get("foo.html"), $.get("bar.html")]).next(function (values) { - log($.map(values, function (v) { return v.length })); - if (values[1].match(/nextUrl:\s*(\S+)/)) { - return $.get(RegExp.$1).next(function (d) { - return d; - }); - } - }). - next(function (d) { - log(d.length); - }); -})(); + next(function () { + alert(3); + }); +}). +next(function () { + alert(4); +}); -// next -(() => { - var d = new Deferred(); - d. - next(function () { - alert(1); - }). - next(function () { - alert(2); - }); - d.call(); -})(); - -// error -(() => { - var d = new Deferred(); - d. - next(function () { - alert(1); - throw "foo"; - }). - next(function () { - alert('not shown'); - }). - error(function (e) { - alert(e); //=> "foo" - }); - d.call(); -})(); - -// call -(() => { - var d = new Deferred(); - setTimeout(function () { - d.call('value'); - }, 100); - return d; -})(); - -// fail (() => { var d = new Deferred(); var x = new XMLHttpRequest(); @@ -92,767 +141,189 @@ interface http { return d; })(); -// chain -(() => { - chain( - function () { - return wait(0.5); - }, - function (w) { - throw "foo"; - }, - function error(e) { - alert(e); - }, - [ - function () { - return wait(1); - }, - function () { - return wait(2); +loop(1000, function (n) { + // heavy process +}); + +next(function () { + console.log("start"); +}). +next(function () { + function pow (x, n) { + function _pow (n, r) { + console.log([n, r]); + if (n == 0) return r; + return call(_pow, n - 1, x * r); } - ], - function (result) { - alert([result[0], result[1]]); - }, - { - foo: wait(1), - bar: wait(1) - }, - function (result) { - alert([result.foo, result.bar]); - }, - function error(e) { - alert(e); - } - ); -})(); + return call(_pow, n, 1); + } + return call(pow, 2, 10); +}). +next(function (r) { + console.log([r, "end"]); +}). +error(function (e) { + alert(e); +}) -// wait -(() => { - wait(1).next(function (elapsed) { - log(elapsed); //=> may be 990-1100 - }); -})(); +$.get("README.markdown").next(function (data) { + console.log(data); +}); -// call -(() => { - next(function () { - function pow(x, n) { - function _pow(n, r) { - print([n, r]); - if (n == 0) return r; - return call(_pow, n - 1, x * r); - } +console.log("start. gathering data."); - return call(_pow, n, 1); - } +parallel([$.get("README.markdown"), $.get("ChangeLog")]). +next(function (values) { + var lengths = $.map(values, function (i) { return i.length }); + console.log(lengths.join(", ")); +}); - return call(pow, 2, 10); +console.log("start. gathering data."); + +parallel({html: $.get("README.markdown"), js: $.get("ChangeLog")}). +next(function (values) { + console.log(["html=", values.html.length, " js=", values.js.length].join("")); +}); + +console.log("start. wait 3 sec."); + +var list = []; +var printAndReturn = function (i) { console.log(i+"msec elapsed"); return i; }; +list.push(wait(0).next(printAndReturn)); +list.push(wait(1).next(printAndReturn)); +list.push(wait(2).next(printAndReturn)); +list.push(wait(3).next(printAndReturn)); + +parallel(list).next(function (values) { + console.log("Completed. values: "+values.join(", ")); +}); + +var queue = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; +var workers = new Array(2); +var work = function (job) { + console.log('working... ' + job); + return wait(Math.random() * 4); +}; + +for (var i = 0, len = workers.length; i < len; i++) { + workers[i] = next(function me () { + var job = queue.shift(); + if (!job) return; + + console.log("start worker: " + job); + return next(function () { return job }). + next(work). + next(me); }). - next(function (r) { - print([r, "end"]); - }); -})(); - -// parallel -(() => { - parallel([ - $.get("foo.html"), - $.get("bar.html") - ]).next(function (values) { - values[0] //=> foo.html data - values[1] //=> bar.html data + error(function (e) { + alert(e); }); +} - parallel({ - foo: $.get("foo.html"), - bar: $.get("bar.html") - }).next(function (values) { - values.foo //=> foo.html data - values.bar //=> bar.html data - }); -})(); +parallel(workers).next(function () { + console.log('all done!'); +}); -// loop -(() => { - //=> loop 1 to 100 - loop({ begin: 1, end: 100, step: 10 }, function (n, o) { +next(function () { + var sum = 0; + return loop({end:100000, step:1000}, function (n: number, o?: any) { + console.log(["Processing divided loop:n=", n, ", sum=", sum, " last?=", o.last].join("")); for (var i = 0; i < o.step; i++) { - log(n + i); + // console.log(i + n); + sum += i + n; } + console.log(["sum=", sum].join("")); + return sum; }); - - //=> loop 10 times with sleeping 1 sec in each loop. - loop(10, function (n) { - log(n); - return wait(1); - }); -})(); - -// repeat -(() => { - repeat(10, function (i) { - i //=> 0,1,2,3,4,5,6,7,8,9 - }); -})(); - -// register -(() => { - // Deferred.register("loop", loop); - - // Global Deferred function - loop(10, function (n) { - print(n); - }). - // Registered Deferred.prototype.loop - loop(10, function (n) { - print(n); - }); -})(); - -// connect -(() => { - var timeout = Deferred.connect(setTimeout, { target: window, ok: 0 }); - timeout(1).next(function () { - alert('after 1 sec'); - }); - - var timeout = Deferred.connect(window, "setTimeout"); - timeout(1).next(function () { - alert('after 1 sec'); - }); -})(); - -// retry -(() => { - Deferred.retry(3, function () { - return http.get('foo.html'); - }). - next(function (res) { - res //=> response if succeeded - }). - error(function (e) { - e //=> error if all try failed - }); -})(); +}). +next(function (e) { + console.log("Result:"+e); + console.log("end"); +}). +error(function (e) { + console.log(e); +}); -/***** Tutorial case *****/ - -(() => { - Deferred.define(); - - next(function () { - alert("Hello!"); - return wait(5); - }). - next(function () { - alert("World!"); - }); - - Deferred.next(function () { - alert("Hello!"); - return Deferred.wait(5); - }). - next(function () { - alert("World!"); - }); - - // http.get is assumed to be a function that takes a URI as an argument and returns a Deferred instance - var results = []; - next(function () { - return http.get("/foo.json").next(function (data) { - results.push(data); - }); - }). - next(function () { - return http.get("/baz.json").next(function (data) { - results.push(data); - }); - }). - next(function () { - return http.get("/baz.json").next(function (data) { - results.push(data); - }); - }). - next(function () { - alert(results); - }); - - var wants = ["/foo.json", "/bar.json", "/baz.json"]; - var results = []; - loop(wants.length, function (i) { - return http.get(wants[i]).next(function (data) { - results.push(data); - }); - }). - next(function () { - alert(results); - }); - - parallel([ - http.get("/foo.json"), - http.get("/bar.json"), - http.get("/baz.json") - ]). - next(function (results) { - alert(results); - }); - - next(function () { - // something 1 - }). - next(function () { - // asynchronous process - throw "error!"; - }). - next(function () { - // something 2 (not executed as an error occurs in the previous process) - }); - - next(function () { - // something 1 - }). - next(function () { - // asynchronous process - throw "error!"; - }). - next(function () { - // something 2 (not executed as an error occurs in the previous process) - }). - error(function (e) { - alert(e); - }); - - next(function () { - // something 1 - }). - next(function () { - // asynchronous process - throw "error!"; - }). - error(function (e) { - alert(e); - }). - next(function () { - // something 2 (executed since the exception would already be handled) - }). - error(function (e) { - alert(e); - }); - - next(function () { - alert("Hello!"); - return wait(5); - }). - next(function () { - alert("World!"); - }); - - next(function () { - alert(1); - return next(function () { - alert(2); - }). - next(function () { - alert(3); - }); - }). - next(function () { - alert(4); - }); - - var http = {} - http.get = function (uri) { - var deferred = new Deferred(); - var xhr = new XMLHttpRequest(); - xhr.onreadystatechange = function () { - if (xhr.readyState == 4) { - if (xhr.status == 200) { - deferred.call(xhr); - } else { - deferred.fail(xhr); - } - } - }; - deferred.canceller = function () { xhr.abort() }; - return deferred; +loop({begin: 1, end:100, step:10}, function (n: number, o?: any) { + console.log(["Processing divided loop:n=", n, " last?=", o.last].join("")); + for (var i = 0; i < o.step; i++) { + var j = n + i; + console.log(j); } +}); - loop(1000, function (n) { - // heavy process - }); - - function repeat(n, f) { - var i = 0, end = {}, ret = null; - return Deferred.next(function () { - var t = (new Date()).getTime(); - divide: { - do { - if (i >= n) break divide; - ret = f(i++); - } while ((new Date()).getTime() - t < 20); - return Deferred.call(arguments.callee); - } - }); +Deferred.repeat(100, function (n, o?) { + console.log(n); + for (var i = 0; i < Math.pow(n, 2); i++) { + for (var j = n; j; j--); } +}); - next(function () { - console.log("start"); - }). - next(function () { - function pow(x, n) { - function _pow(n, r) { - console.log([n, r]); - if (n == 0) return r; - return call(_pow, n - 1, x * r); - } +loop(10, function (n) { + console.log(n); + return wait(0.1); +}); - return call(_pow, n, 1); - } +loop(10, function (n) { + console.log(String.fromCharCode(97+n)); + return wait(0.2); +}); - return call(pow, 2, 10); - }). - next(function (r) { - console.log([r, "end"]); - }). - error(function (e) { - alert(e); - }) +console.log(0); +loop(10, function (n) { + console.log(n); + return n; +}). +wait(1). +loop(10, function (n) { + var c = String.fromCharCode(97+n); + console.log(c); + return c; +}). +next(function (i) { + console.log("end"); +}). +error(function (e) { + alert(e); +}); - loop(10, function (i) { - console.log(i) - }); +loop(5, function (i, o?) { + console.log(i); + return o.last? i : wait(1); +}). +next(function (e) { + console.log("end ["+e+"]"); +}). +error(function (e) { + console.log(e); +}); - $.get("README.markdown").next(function (data) { - console.log(data); - }); - -})(); - -(() => { - console.log("start. gathering data."); - - parallel([$.get("README.markdown"), $.get("ChangeLog")]). - next(function (values) { - var lengths = $.map(values, function (i) { return i.length }); - console.log(lengths.join(", ")); - }); -})(); - -(() => { - console.log("start. gathering data."); - - parallel({ html: $.get("README.markdown"), js: $.get("ChangeLog") }). - next(function (values) { - console.log(["html=", values.html.length, " js=", values.js.length].join("")); - }); -})(); - -(() => { - console.log("start. wait 3 sec."); - - var list = []; - var printAndReturn = function (i) { - console.log(i + "msec elapsed"); - return i; - }; - list.push(wait(0).next(printAndReturn)); - list.push(wait(1).next(printAndReturn)); - list.push(wait(2).next(printAndReturn)); - list.push(wait(3).next(printAndReturn)); - - parallel(list).next(function (values) { - console.log("Completed. values: " + values.join(", ")); - }); -})(); - -(() => { - var queue = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - var workers = new Array(2); - var work = function (job) { - console.log('working... ' + job); - return wait(Math.random() * 4); - }; - - for (var i = 0, len = workers.length; i < len; i++) { - workers[i] = next(function me() { - var job = queue.shift(); - if (!job) return; - - console.log("start worker: " + job); - return next(function () { return job }). - next(work). - next(me); - }). - error(function (e) { - alert(e); - }); - } - - parallel(workers).next(function () { - console.log('all done!'); - }); -})(); - -(() => { - next(function () { - var sum = 0; - return loop({ end: 100000, step: 1000 }, function (n, o) { - console.log(["Processing divided loop:n=", n, ", sum=", sum, " last?=", o.last].join("")); - for (var i = 0; i < o.step; i++) { - // console.log(i + n); - sum += i + n; - } - console.log(["sum=", sum].join("")); - return sum; - }); - }). - next(function (e) { - console.log("Result:" + e); - console.log("end"); - }). - error(function (e) { - console.log(e); - }); -})(); - -(() => { - loop({ begin: 1, end: 100, step: 10 }, function (n, o) { - console.log(["Processing divided loop:n=", n, " last?=", o.last].join("")); - for (var i = 0; i < o.step; i++) { - var j = n + i; - console.log(j); - } - }); -})(); - -(() => { - Deferred.repeat(100, function (n, o) { - console.log(n); - for (var i = 0; i < Math.pow(n, 2); i++) { - for (var j = n; j; j--); - } - }); -})(); - -(() => { - loop(10, function (n) { - console.log(n); - return wait(0.1); - }); - - loop(10, function (n) { - console.log(String.fromCharCode(97 + n)); - return wait(0.2); - }); -})(); - -(() => { - console.log(0); - loop(10, function (n) { - console.log(n); - return n; - }). - wait(1). - loop(10, function (n) { - var c = String.fromCharCode(97 + n); - console.log(c); - return c; - }). - next(function (i) { - console.log("end"); - }). - error(function (e) { - alert(e); - }); -})(); - -(() => { - loop(5, function (i, o) { - console.log(i); - return o.last ? i : wait(1); - }). - next(function (e) { - console.log("end [" + e + "]"); - }). - error(function (e) { - console.log(e); - }); -})(); - -(() => { - next(function (i) { - function delayloop(i) { - console.log(i++); - if (i < 5) { - return wait(1).next(function () { - return call(delayloop, i); - }); - } - } - - return call(delayloop, 0); - }). - next(function (e) { - console.log("end"); - }). - error(function (e) { - console.log(e); - }); -})(); - -(() => { - function callcc(fun) { - var error = new Deferred(); - return call(function () { - // JSDeferred passes current Deferred Object to this. - var ccdeferred = this; - // Call with current continuation (calling Deferred.next) - return fun(function (a) { - ccdeferred._next.call(a); - throw error +next(function (i) { + function delayloop (i) { + console.log(i++); + if (i < 5) { + return wait(1).next(function () { + return call(delayloop, i); }); - }). - error(function (e) { - // Current Deferred chain must be stopped - if (e === error) { - return e; - } else { - throw e; - } - }); - } - - callcc(function (cont) { - return 10 * 10 * cont(20); - }). - next(function (val) { - console.log("callcc1 returns:" + val); - }); - // should show "callcc1 returns:20" - - var cont; - var i = 0; - callcc(function (c) { - cont = c; - return 10; - }). - next(function (val) { - console.log("callcc2 returns:" + val); - if (!i++) cont(20); - }); - // should show "callcc2 returns:10", "callcc returns:20" -})(); - -(() => { - function callcc(fun) { - var error = new Deferred(); - return call(function () { - // JSDeferred passes current Deferred Object to this. - var ccdeferred = this; - // Call with current continuation (calling Deferred.next) - return fun(function (a) { - ccdeferred._next.call(a); - throw error - }); - }). - error(function (e) { - // Current Deferred chain must be stopped - if (e === error) { - return e; - } else { - throw e; - } - }); - } - - // http://www.sampou.org/scheme/t-y-scheme/t-y-scheme-Z-H-16.html#node_chap_14 - // Just port above. - function amb() { - var alts = arguments; - var prevAmbFail = amb.ambFail; - - return callcc(function (sk) { - return loop(alts.length, function (i) { - var alt = alts[i]; - return callcc(function (fk) { - amb.ambFail = function () { - amb.ambFail = prevAmbFail; - return fk("fail"); - }; - return sk(alt); - }); - }). - next(prevAmbFail); - }); - } - - amb.ambFail = function () { throw "amb tree exhausted" }; - - // Utility function - function amb1(ambvars) { - var f = wait(0); - var vars = {}; - for (var k in ambvars) if (ambvars.hasOwnProperty(k)) (function (name, val) { - console.log(name); - f = f.next(function () { - return amb.apply(this, val).next(function (i) { - vars[name] = i; - return vars; - }); - }); - })(k, ambvars[k]); - - return f; - } - - function assert(cond) { - if (!cond) throw amb(); - } - - // http://mayokara.info/note/view/251 - Array.prototype.uniq = function () { - for (var i = 0, l = this.length; i < l; i++) { - if (this.indexOf(this[i]) < i) { - this.splice(i--, l-- && 1); - } } - return this; - }; + } + return call(delayloop, 0); +}). +next(function (e) { + console.log("end"); +}). +error(function (e) { + console.log(e); +}); - amb1({ - baker: [1, 2, 3, 4, 5], - cooper: [1, 2, 3, 4, 5], - fletcher: [1, 2, 3, 4, 5], - miller: [1, 2, 3, 4, 5], - smith: [1, 2, 3, 4, 5] - }). - next(function (vars) { - with (vars) { - console.log(vars); - // 簡易 distinct - assert([baker, cooper, fletcher, miller, smith].uniq().length == 5); - console.log("distinct passed"); - assert(baker != 5); - assert(cooper != 1); - assert(fletcher != 1 && fletcher != 5); - assert(miller > cooper); - assert(Math.abs(smith - fletcher) != 1); - assert(Math.abs(fletcher - cooper) != 1); +var deferred = new Deferred(); +$("#step-run").click(function () { deferred.call() }); - return vars; - } - }). - next(function (vars) { - with (vars) { - console.log("solved"); - console.log(vars); - alert(uneval(vars)); - } - }). - error(function (e) { - alert(e) - }); -})(); - -(() => { - var d1 = new Deferred(); - d1.callback.ok = function () { - alert("1"); - }; - - var d2 = new Deferred(); - d2.callback.ok = function () { - alert("2"); - }; - - // Set d2 as continuation of d1. - d1._next = d2; - - // Invoke the chain. - d1.call(); -})(); - -(() => { - next(function () { // this `next` is global function - alert("1"); - }). - next(function () { // this `next` is Deferred#next - alert("2"); - }). - next(function () { - alert("3"); - }); -})(); - -(() => { - next(function () { - alert("1"); - }). - next(function () { - alert("2"); - // child Deferred - return next(function () { - alert("3"); - }); - }). - next(function () { - alert("4"); - }); -})(); - -(() => { - next(function () { - alert("1"); - }). - next(function () { - alert("2"); - var d = next(function () { - alert("3"); - }); - d._next = this._next; - this.cancel(); - }). - next(function () { - alert("4"); - }); -})(); - -(() => { - next(function () { - alert("1"); - }). - next(function () { - alert("2"); - next(function () { - alert("3"); - }). - next(function () { - alert("4"); - }); - }); -})(); - -(() => { - next(function () { - throw "Error"; - }). - error(function (e) { - expect("Errorback called", "Error", e); - return e; // recovering error - }). - next(function (e) { - expect("Callback called", "Error", e); - throw "Error2"; - }). - next(function (e) { - // This process is not called because - // the error is not recovered. - ng("Must not be called!!"); - }). - error(function (e) { - expect("Errorback called", "Error2", e); - }); -})(); +loop(5, function (i) { + console.log("running... " + i); + return deferred; +}). +next(function () { + console.log("completed"); +}); diff --git a/jsdeferred/jsdeferred.d.ts b/jsdeferred/jsdeferred.d.ts index a896ac2c1..27a4fb65a 100644 --- a/jsdeferred/jsdeferred.d.ts +++ b/jsdeferred/jsdeferred.d.ts @@ -3,10 +3,12 @@ // Definitions by: Daisuke Mino // Definitions: https://github.com/borisyankov/DefinitelyTyped +/// + interface Loop { - begin: number; - end: number; - step: number; + begin?: number; + end?: number; + step?: number; } interface ConnectOption { @@ -22,7 +24,7 @@ interface RetryOption { interface DeferredizedFunction { (...arg: any[]): Deferred; } interface DeferredizedFunctionWithNumber { (n: number): Deferred; } -interface FunctionWithNumber { (i: number); } +interface FunctionWithNumber { (i: number, o?: any); } interface ErrorCallback { (d: Deferred, ...args: any[]); } declare class Deferred { @@ -62,6 +64,9 @@ declare class Deferred { loop(n: Loop, fun: FunctionWithNumber): Deferred; } +interface JQueryXHR { + next(fun: Function): Deferred; +} declare function chain(...args: any[]): Deferred; declare function wait(n: number): Deferred; @@ -72,4 +77,7 @@ declare function earlier(dl: any): Deferred; declare function loop(n: number, fun: FunctionWithNumber): Deferred; declare function loop(n: Loop, fun: FunctionWithNumber): Deferred; -declare function repeat(n: number, fun: FunctionWithNumber): Deferred; \ No newline at end of file +declare function repeat(n: number, fun: FunctionWithNumber): Deferred; + +declare function next(fun: Function): Deferred; + diff --git a/slickgrid/SlickGrid-tests.ts b/slickgrid/SlickGrid-tests.ts index c93a2704b..a5fa63e03 100644 --- a/slickgrid/SlickGrid-tests.ts +++ b/slickgrid/SlickGrid-tests.ts @@ -157,7 +157,7 @@ grid.getCellCssStyles("test")[0]["number_column"]; grid.getCellEditor(); -grid.getCellFromEvent(new Slick.SlickEvent()); +grid.getCellFromEvent(new Slick.Event()); grid.getCellFromPoint(5, 10); diff --git a/slickgrid/SlickGrid.d.ts b/slickgrid/SlickGrid.d.ts index 50c7c2904..ac7ce64e7 100644 --- a/slickgrid/SlickGrid.d.ts +++ b/slickgrid/SlickGrid.d.ts @@ -1,4 +1,4 @@ -/* +/* SlickGrid-2.1.d.ts may be freely distributed under the MIT license. Copyright (c) 2013 Josh Baldwin https://github.com/jbaldwin/SlickGrid.d.ts @@ -26,6 +26,8 @@ OTHER DEALINGS IN THE SOFTWARE. /// +interface DOMEvent extends Event {} + declare module Slick { /** @@ -71,11 +73,10 @@ declare module Slick { /*** * A simple publisher-subscriber implementation. - * todo: SlickEvent is named 'Event', but this clashes with the native DOM Event which is also used is various places. * @class Event * @constructor */ - export class SlickEvent { + export class Event { constructor(); @@ -110,8 +111,8 @@ declare module Slick { * @return Last run callback result. * @note slick.core.Event.notify shows this method as returning a value, type is unknown. */ - public notify(args: T, e: EventData, scope: any): any; - public notify(args: T, e: Event, scope: any): any; + public notify(args?: T, e?: EventData, scope?: any): any; + public notify(args?: T, e?: DOMEvent, scope?: any): any; } @@ -710,7 +711,7 @@ declare module Slick { **/ destroy(): void; - onSelectedRangesChanged: Slick.SlickEvent; + onSelectedRangesChanged: Slick.Event; } export class Grid { @@ -967,7 +968,7 @@ declare module Slick { * @param e A standard W3C/jQuery event. * @return **/ - public getCellFromEvent(e: SlickEvent): Cell; // todo: !! Unsure on return type !! + public getCellFromEvent(e: Event): Cell; // todo: !! Unsure on return type !! /** * Returns a hash containing row and cell indexes. Coordinates are relative to the top left corner of the grid beginning with the first row (not including the column headers). @@ -1108,38 +1109,39 @@ declare module Slick { // #region Events - public onScroll: Slick.SlickEvent; - public onSort: Slick.SlickEvent>; - public onHeaderMouseEnter: Slick.SlickEvent>; - public onHeaderMouseLeave: Slick.SlickEvent>; - public onHeaderContextMenu: Slick.SlickEvent>; - public onHeaderClick: Slick.SlickEvent>; - public onHeaderCellRendered: Slick.SlickEvent>; - public onBeforeHeaderCellDestroy: Slick.SlickEvent>; - public onHeaderRowCellRendered: Slick.SlickEvent>; - public onBeforeHeaderRowCellDestroy: Slick.SlickEvent>; - public onMouseEnter: Slick.SlickEvent; - public onMouseLeave: Slick.SlickEvent; - public onClick: Slick.SlickEvent; - public onDblClick: Slick.SlickEvent; - public onContextMenu: Slick.SlickEvent; - public onKeyDown: Slick.SlickEvent; - public onAddNewRow: Slick.SlickEvent>; - public onValidationError: Slick.SlickEvent>; - public onColumnsReordered: Slick.SlickEvent; - public onColumnsResized: Slick.SlickEvent; - public onCellChange: Slick.SlickEvent>; - public onBeforeEditCell: Slick.SlickEvent>; - public onBeforeCellEditorDestroy: Slick.SlickEvent>; - public onBeforeDestroy: Slick.SlickEvent; - public onActiveCellChanged: Slick.SlickEvent; - public onActiveCellPositionChanged: Slick.SlickEvent; - public onDragInit: Slick.SlickEvent; - public onDragStart: Slick.SlickEvent; - public onDrag: Slick.SlickEvent; - public onDragEnd: Slick.SlickEvent; - public onSelectedRowsChanged: Slick.SlickEvent; - public onCellCssStylesChanged: Slick.SlickEvent; + public onScroll: Slick.Event; + public onSort: Slick.Event>; + public onHeaderMouseEnter: Slick.Event>; + public onHeaderMouseLeave: Slick.Event>; + public onHeaderContextMenu: Slick.Event>; + public onHeaderClick: Slick.Event>; + public onHeaderCellRendered: Slick.Event>; + public onBeforeHeaderCellDestroy: Slick.Event>; + public onHeaderRowCellRendered: Slick.Event>; + public onBeforeHeaderRowCellDestroy: Slick.Event>; + public onMouseEnter: Slick.Event; + public onMouseLeave: Slick.Event; + public onClick: Slick.Event; + public onDblClick: Slick.Event; + public onContextMenu: Slick.Event; + public onKeyDown: Slick.Event; + public onAddNewRow: Slick.Event>; + public onValidationError: Slick.Event>; + public onColumnsReordered: Slick.Event; + public onColumnsResized: Slick.Event; + public onCellChange: Slick.Event>; + public onBeforeEditCell: Slick.Event>; + public onBeforeCellEditorDestroy: Slick.Event>; + public onBeforeDestroy: Slick.Event; + public onActiveCellChanged: Slick.Event; + public onActiveCellPositionChanged: Slick.Event; + public onDragInit: Slick.Event; + public onDragStart: Slick.Event; + public onDrag: Slick.Event; + public onDragEnd: Slick.Event; + public onSelectedRowsChanged: Slick.Event; + public onCellCssStylesChanged: Slick.Event; + public onViewportChanged: Slick.Event; // #endregion Events // #region Plugins @@ -1335,6 +1337,10 @@ declare module Slick { scrollTop: number; } + export interface OnViewportChangedEventData { + + } + export interface Cell { row: number; cell: number; @@ -1435,7 +1441,7 @@ declare module Slick { export class LongText extends Editor { constructor(args: EditorOptions); - public handleKeyDown(e: Event): void; + public handleKeyDown(e: DOMEvent): void; public save(): void; public cancel(): void; public hide(): void; @@ -1469,7 +1475,7 @@ declare module Slick { **/ export class DataView implements DataProvider { - constructor(options: DataViewOptions); + constructor(options?: DataViewOptions); public beginUpdate(): void; public endUpdate(): void; @@ -1527,7 +1533,7 @@ declare module Slick { public getItemByIdx(): T; public mapRowsToIds(rowArray: T[]): string[]; public setRefreshHints(hints: RefreshHints): void; - public setFilterArgs(hints: RefreshHints): void; + public setFilterArgs(args: any): void; public refresh(): void; public updateItem(id: string, item: T): void; public insertItem(insertBefore: number, item: T): void; @@ -1540,9 +1546,9 @@ declare module Slick { public getItem(index: number): SlickData; public getItemMetadata(): void; - public onRowCountChanged: Slick.SlickEvent; - public onRowsChanged: Slick.SlickEvent; - public onPagingInfoChanged: Slick.SlickEvent; + public onRowCountChanged: Slick.Event; + public onRowsChanged: Slick.Event; + public onPagingInfoChanged: Slick.Event; } export interface GroupingOptions { @@ -1672,8 +1678,8 @@ declare module Slick { // public setSort(): any; // public setSearch(): any; - // public onDataLoading: Slick.SlickEvent; - // public onDataLoaded: Slick.SlickEvent; + // public onDataLoading: Slick.Event; + // public onDataLoaded: Slick.Event; //} @@ -1696,5 +1702,5 @@ declare module Slick { export interface PluginOptions { // extend your plugin options here } -} +}