diff --git a/blocks/blocks-tests.ts b/blocks/blocks-tests.ts
index 5adc719e8d..7b83b52a61 100644
--- a/blocks/blocks-tests.ts
+++ b/blocks/blocks-tests.ts
@@ -1,7 +1,7 @@
///
function test_blocks_methods() {
- var extended;
+ var extended: Object;
blocks.extend(extended, new Object());
blocks.each([3, 1, 4], function(value, index, collection) {
@@ -24,7 +24,7 @@ function test_blocks_methods() {
// -> false
}
- function max(collection, callback) {
+ function max(collection: any, callback: any) {
callback = callback || blocks.noop;
}
@@ -119,21 +119,19 @@ function test_blocks_methods() {
blocks.isPlainObject(new Object());
// -> true
- function Car() {
+ var car = new Object();
- }
-
- blocks.isPlainObject(new Car());
+ blocks.isPlainObject(car);
// -> false
- var alert = blocks.bind(function() {
+ var alert = blocks.bind(() => {
alert(this);
}, 'Hello bind method!');
alert();
// -> alerts 'Hello bind method'
- var alertAll = blocks.bind(function(firstName, lastName) {
+ var alertAll = blocks.bind((firstName: string, lastName: string) => {
alert('My name is ' + firstName + ' ' + lastName);
}, null, 'John', 'Doe');
@@ -150,16 +148,16 @@ function test_blocks_methods() {
message: 'Hello World!'
});
- blocks.query({
+ blocks.query({
items: ['John', 'Alf', 'Mega'],
- alertIndex: function(e) {
+ alertIndex: (e: any) => {
alert('Clicked an item with index:' + blocks.context(e.target).$index);
}
});
blocks.query({
items: [1, 2, 3],
- alertValue: function(e) {
+ alertValue: (e: any) => {
alert('Clicked the value: ' + blocks.dataItem(e.target));
}
});
@@ -177,15 +175,6 @@ function test_blocks_methods() {
// -> 305
}
-function test_observable() {
- blocks.observable['formatter'] = () => {
- // your code here
- };
-
- // extending using the formatter extender
- var data = blocks.observable([1, 2, 3]).extend('formatter');
-}
-
function test_observable_array() {
// creates an observable array with [1, 2, 3] as values
var items = blocks.observable([1, 2, 3]);
@@ -272,7 +261,7 @@ function test_Collection() {
var Users = App.Collection(User, {
count: App.Property({
- value: function() {
+ value: () => {
return this().length;
}
})
@@ -293,18 +282,18 @@ function test_View() {
var App = blocks.Application();
App.View('Clicker', {
- handleClick: function() {
+ handleClick: () => {
alert('Clicky! Click!');
}
});
App.View('Statistics', {
- init: function() {
+ init: () => {
this.loadRemoteData();
},
- loadRemoteData: function() {
+ loadRemoteData: () => {
// ...stuff...
}
});
@@ -314,7 +303,7 @@ function test_View() {
route: 'contactus'
},
- routed: function() {
+ routed: () => {
alert('Navigated to ContactUs page!')
}
});
@@ -326,7 +315,7 @@ function test_View() {
});
App.View('Navigation', {
- navigateToContactUs: function() {
+ navigateToContactUs: () => {
this.route('contactus')
}
});
diff --git a/blocks/blocks.d.ts b/blocks/blocks.d.ts
index aedef9d04c..ad492333e6 100644
--- a/blocks/blocks.d.ts
+++ b/blocks/blocks.d.ts
@@ -27,7 +27,7 @@ interface BlocksStatic {
/**
* Copies properties from all provided objects into the first object parameter
*/
- extend(obj: Object, ...objects): void;
+ extend(obj: Object, ...objects: any[]): void;
/**
* Iterates over the collection
@@ -173,7 +173,7 @@ interface BlocksStatic {
* @param thisArg The new this binding context value
* @param args Optional arguments that will be passed to the function
*/
- bind(func: Function, thisArg: any, ...args): Function;
+ bind(func: Function, thisArg: any, ...args: any[]): Function;
/**
* Determines if two values are deeply equal. Set deepEqual to false to stop recusively equality checking
@@ -228,11 +228,11 @@ interface BlocksStatic {
/**
* Creates the server which will automatically handle server-side rendering.
*/
- server(): { express() };
+ server(): { express(): any };
/**
* @param options Overrides default jsblocks options
*/
- server(options: Server): { express() };
+ server(options: Server): { express(): any };
/**
* Make observable property. You can specify initial value in parentheses.
@@ -253,7 +253,7 @@ interface BlocksStatic {
/////////////////////////////////////////
interface BlocksObservable extends Extendable {
- (any): BlocksObservable;
+ (arg: any): BlocksObservable;
/**
* Updates all elements, expressions and dependencies where the observable is used
@@ -287,12 +287,12 @@ interface BlocksArray extends BlocksObservable {
*
* @param options Optional options
*/
- extend(...options): BlocksArray;
+ extend(...options: any[]): BlocksArray;
/**
* @param name Name of the extender
* @param options Optional options
*/
- extend(name: string, ...options): BlocksArray;
+ extend(name: string, ...options: any[]): BlocksArray;
/**
* Removes all items from the collection and replaces them with the new value provided.
@@ -419,7 +419,7 @@ interface BlocksArray extends BlocksObservable {
*
* @param values The item(s) to add to the observable array
*/
- push(...values): number;
+ push(...values: any[]): number;
/**
* Reverses the order of the elements in the observable array
@@ -576,7 +576,7 @@ interface ViewPrototype {
ready?: Function;
options?: {
- route?: any,
+ route?: any;
url?: string
};
}
@@ -636,12 +636,12 @@ interface ModelPrototype {
isNew?(): boolean;
options?: {
- idAttr?: string,
- baseUrl?: string,
- read?: { url?: string },
- create?: { url?: string },
- destroy?: { url?: string },
- update?: { url?: string },
+ idAttr?: string;
+ baseUrl?: string;
+ read?: { url?: string };
+ create?: { url?: string };
+ destroy?: { url?: string };
+ update?: { url?: string };
};
}
@@ -677,10 +677,10 @@ interface Collection extends Extendable {
interface CollectionPrototype {
options?: {
- read?: { url?: string },
- create?: { url?: string },
- destroy?: { url?: string },
- update?: { url?: string },
+ read?: { url?: string };
+ create?: { url?: string };
+ destroy?: { url?: string };
+ update?: { url?: string };
};
}
@@ -694,8 +694,8 @@ interface Extendable {
* @param name Name of the extender
* @param options Optional options
*/
- extend(name?: string, ...options): T;
- extend(any): T;
+ extend(name?: string, ...options: any[]): T;
+ extend(arg: any): T;
}
interface Server {
@@ -703,25 +703,25 @@ interface Server {
/**
* The port at which your application will be run
*/
- port?: number,
+ port?: number;
/**
- * The folder where your application files like .html, .js and .css are going to be.
+ * The folder where your application files like .html; .js and .css are going to be.
* The value is passed to express.static() middleware.
*/
- static?: string,
+ static?: string;
/**
* Caches pages result instead of executing them each time.
* Disabling cache could impact performance.
*/
- cache?: boolean,
+ cache?: boolean;
/**
* Provide an express middleware function or an array of middleware functions.
- * Use: [compression(), bodyParser()]
+ * Use: [compression(); bodyParser()]
*/
- use?: any,
+ use?: any;
}
declare var blocks: BlocksStatic;