forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ko.plus.d.ts
157 lines (121 loc) · 4.05 KB
/
ko.plus.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// Type definitions for ko.plus v0.0.24
// Project: https://github.com/stevegreatrex/ko.plus
// Definitions by: Howard Richards <https://github.com/conficient>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../jquery/jquery.d.ts" />
/// <reference path="../knockout/knockout.d.ts" />
/**
*
* Extensions to KO to provide a command, editable and sortable patterns
* - available at http://www.nuget.org/packages/ko.plus/
*
* (requires TypeScript version 1.4 or higher)
*
* Version 1.0 - initial commit
*
* Version 1.1 - fixed bug - makeEditable is now a function on .editable
* also refactored how the Editable classes inherit to simplify
*
* Version 1.2 - amended callback on commmand.fail() method - accepts response,
* status and message values
*/
//
// Add methods to the 'ko' Knockout object
//
interface KnockoutStatic {
// create a command - two overloads
command: (param: Function | KoPlus.CommandOptions) => KoPlus.Command;
editable: KoPlus.EditableStatic;
editableArray: KoPlus.EditableArrayStatic;
}
//#region Sortable type extensions
//
// extends the KnockoutObservableArray to add sorting methods
// see https://github.com/stevegreatrex/ko.plus#properties-and-functions
//
interface KnockoutObservableArray<T> {
sortKey: KnockoutObservable<string>;
sortDescending: KnockoutObservable<boolean>;
setSourceKey: (key: string) => void;
}
//#endregion
//
// declare new binding handlers in ko.plus
//
interface KnockoutBindingHandlers {
loadingWhen: KnockoutBindingHandler;
command: KnockoutBindingHandler;
sortBy: KnockoutBindingHandler;
}
//
// namespace for ko.plus types
//
declare module KoPlus {
//#region Command types
//
// the Command interface - returned by ko.command(..)
//
export interface Command {
// execute the command
(): void;
//
// properties: https://github.com/stevegreatrex/ko.plus#properties
//
isRunning: KnockoutObservable<boolean>;
canExecute: KnockoutComputed<boolean>;
failed: KnockoutObservable<boolean>;
completed: KnockoutObservable<boolean>;
//
// functions
// see https://github.com/stevegreatrex/ko.plus#functions
//
done: (callback: (data: any) => void) => Command;
fail: (callback: (response: any, status?: string, statusText?:string) => void) => Command;
always: (callback: Function) => Command;
then: (resolve: Function, reject: Function) => Command;
}
//
// options when defining a command using the option method
// see https://github.com/stevegreatrex/ko.plus#options
//
export interface CommandOptions {
// [required] sets the command action method
action: Function;
// [optional] function to determine if command can be executed
canExecute?: () => boolean;
// [optional] context to use in the command
context?: any;
}
//#endregion
//#region Editable types
export interface EditableStatic extends KnockoutObservableStatic {
<T>(value?: T): Editable<T>;
makeEditable(target: any): void;
}
export interface EditableArrayStatic extends KnockoutObservableArrayStatic {
<T>(value?: Array<T>): EditableArray<T>;
makeEditable(target: any): void; //>
}
//
// defines common editable functions and isEditing property
// (used by both editable and editableArray
//
export interface EditableFunctions {
isEditing: KnockoutObservable<boolean>;
beginEdit(): void;
endEdit(): void;
cancelEdit(): void;
rollback(): void;
}
//
// extend the standard KnockoutObservable to add editable functions
//
export interface Editable<T> extends KnockoutObservable<T>, EditableFunctions {
}
//
// extend the standard KnockoutObservableArray to add editable functions
//
export interface EditableArray<T> extends KnockoutObservableArray<T>, EditableFunctions {
}
//#endregion
}