forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ko.plus.d.ts
155 lines (119 loc) · 3.92 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
// Type definitions for ko.plus v0.0.21
// Project: https://github.com/stevegreatrex/ko.plus
// Definitions by: Howard Richards <https://github.com/conficient>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <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
*/
//
// Add methods to the 'ko' Knockout object
//
interface KnockoutStatic {
// create a command - two overloads
command: (param: KoPlus.Callback | 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 {
// predefine a callback type
export type Callback = () => void;
//#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: (error: string) => void) => Command;
always: (callback: Callback) => Command;
then: (resolve: Callback, reject: Callback) => 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: Callback;
// [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
}