Improve Sammy.js declarations

This commit is contained in:
Boris Yankov
2012-10-29 19:57:25 +02:00
parent 6db4460328
commit d7c856dc47
2 changed files with 40 additions and 34 deletions
+31 -25
View File
@@ -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;
+9 -9
View File
@@ -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());