From d7c856dc479c7ae488ee8fc66c6b4db1d6f3b6a7 Mon Sep 17 00:00:00 2001 From: Boris Yankov Date: Mon, 29 Oct 2012 19:57:14 +0200 Subject: [PATCH] Improve Sammy.js declarations --- Definitions/sammyjs-0.7.d.ts | 56 ++++++++++++++++++++---------------- Tests/sammyjs-tests.ts | 18 ++++++------ 2 files changed, 40 insertions(+), 34 deletions(-) diff --git a/Definitions/sammyjs-0.7.d.ts b/Definitions/sammyjs-0.7.d.ts index 42723157a5..8582eb3ccf 100644 --- a/Definitions/sammyjs-0.7.d.ts +++ b/Definitions/sammyjs-0.7.d.ts @@ -130,7 +130,7 @@ module Sammy { load(location: any, options?: any, callback?: Function): any; loadPartials(partials); notFound(): any; - partial(location, data, callback, partials); + partial(location: string, data: any, callback: Function, partials): RenderContext; redirect(...params: any[]): void; render(location: string, data: any, callback: Function, partials): RenderContext; renderEach(location: any, name?: string, data?: any, callback?: Function): RenderContext; @@ -142,17 +142,21 @@ module Sammy { export interface FormBuilder { constructor (name, object); - checkbox(keypath, value, attributes); - close(); - hidden(keypath, attributes); - label(keypath, content, attributes); - open(attributes); - password(keypath, attributes); - radio(keypath, value, attributes); - select(keypath, options, attributes); - submit(attributes); - text(keypath, attributes); - textarea(keypath, attributes); + checkbox(keypath: string, value: any, ...attributes: any[]): string; + close(): string; + hidden(keypath: string, ...attributes: any[]): string; + label(keypath: string, content: any, ...attributes: any[]): string; + open(...attributes: any[]); + password(keypath: string, ...attributes: any[]): string; + radio(keypath: string, value: any, ...attributes: any[]): string; + select(keypath: string, options: any, ...attributes: any[]): string; + submit(...attributes: any[]): string; + text(keypath: string, ...attributes: any[]): string; + textarea(keypath: string, ...attributes: any[]): string; + } + + export interface Form { + formFor(name: string, object: any, content_callback: Function): FormBuilder; } export interface GoogleAnalytics { @@ -199,20 +203,23 @@ module Sammy { } export interface Store { + + stores: any; + constructor (options); - clear(key); - clearAll(); - each(callback); - exists(key); - fetch(key, callback); - filter(callback); - first(callback); - get(key); - isAvailable(); - keys(); - load(key, path, callback); - set(key, value); + clear(key: string): any; + clearAll(): void; + each(callback: Function): bool; + exists(key: string): bool; + fetch(key: string, callback: Function): any; + filter(callback: Function): bool; + first(callback: Function): bool; + get(key: string): any; + isAvailable(): bool; + keys(): string[]; + load(key: string, path: string, callback: Function): void; + set(key: string, value: any): any; Cookie(name, element, options); Data(name, element); @@ -222,7 +229,6 @@ module Sammy { isAvailable(type); Template(app, method_alias); } - } interface JQueryStatic { sammy: Sammy; diff --git a/Tests/sammyjs-tests.ts b/Tests/sammyjs-tests.ts index e6249c78a4..588d08f2c6 100644 --- a/Tests/sammyjs-tests.ts +++ b/Tests/sammyjs-tests.ts @@ -113,9 +113,9 @@ function test_app() { var app = $.sammy(function () { var _this: Sammy.Application; _this.mapRoutes([ - ['get', '#/', function () { _this.log('index'); }], + ['get', '#/', function () { }], ['post', '#/create', 'addUser'], - [/dowhatever/, function () { _this.log(_this.verb, _this.path) }]; + [/dowhatever/, function () { }] ]); }); @@ -156,7 +156,6 @@ function test_app() { var _this: Sammy.Application; _this.use(MyPlugin, '_this is my plugin'); _this.get('#/', function () { - _this.myhelper('and dont you forget it!'); }); }); @@ -172,6 +171,7 @@ function test_misc() { var _this: Sammy.Application; _this.setLocationProxy(new Sammy.DataLocationProxy(_this, 'location', 'rel')); _this.get('about', function () { + var _this: Sammy.EventContext; _this.partial('about.html'); }); }); @@ -488,7 +488,7 @@ function test_events() { function test_plugins() { var MyPlugin = function (app) { - var _this: Sammy.Application; + var _this: Sammy.Application; _this.helpers({ alert: function (message) { _this.log("ALERT! " + message); @@ -496,15 +496,15 @@ function test_plugins() { }); }; var app = $.sammy(function () { - var _this: Sammy.Application; + var _this: Sammy.Application; _this.use(MyPlugin); _this.get('#/', function () { - var _this: Sammy.EventContext; + var _this: Sammy.EventContext; _this.alert("I'm home"); }); }); var MyAdvancedPlugin = function (app, prefix, suffix) { - var _this: Sammy.Application; + var _this: Sammy.Application; _this.helpers({ alert: function (message) { _this.log(prefix, message, suffix); @@ -513,7 +513,7 @@ function test_plugins() { }; var app = $.sammy(function () { - var _this: Sammy.Application; + var _this: Sammy.Application; _this.use(MyAdvancedPlugin, 'BEFORE!', 'AFTER!'); _this.get('#/', function () { _this.alert("I'm home"); @@ -521,7 +521,7 @@ function test_plugins() { }); var dbLoadAndDisplay = function (app) { - var _this: Sammy.Application; + var _this: Sammy.Application; _this.get('#/', function () { _this.record = _this.app.db[_this.app.element_selector]; _this.app.swap(_this.record.toHTML());