Fixed bug - makeEditable now on .editable

Also refactored how editable types inherit - now simpler
This commit is contained in:
HowardRichards 2015-02-18 11:19:52 +00:00
parent 74ba1baa4b
commit 2a67c1e923
2 changed files with 27 additions and 35 deletions

View File

@ -9,6 +9,8 @@
/*
Version 1.0 - initial commit
Version 1.1 - added test for makeEditable
Note: Typescript version 1.4 or higher is required for union types
and type declarations
*/
@ -65,6 +67,8 @@ function EditableTests() {
var edit4 = ko.editable<string|number>(1); // with union types
var edit5 = ko.editable<string|number>("test");
ko.editable.makeEditable(this);
// test getting the value
var value = edit1();

58
ko.plus/ko.plus.d.ts vendored
View File

@ -14,14 +14,14 @@
*
* 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;
@ -29,7 +29,6 @@ interface KnockoutStatic {
editableArray: KoPlus.EditableArrayStatic;
}
//#region Sortable type extensions
//
@ -46,12 +45,10 @@ interface KnockoutObservableArray<T> {
//#endregion
//
// declare new binding handlers in ko-plus
// declare new binding handlers in ko.plus
//
interface KnockoutBindingHandlers {
loadingWhen: KnockoutBindingHandler;
command: KnockoutBindingHandler;
@ -60,14 +57,12 @@ interface KnockoutBindingHandlers {
}
//
// namespace for ko-plus types
// namespace for ko.plus types
//
declare module KoPlus {
// predefine a callback type
export type Callback = () => void;
//#region Command types
//
@ -78,7 +73,7 @@ declare module KoPlus {
(): void;
//
// properties: https://github.com/stevegreatrex/ko.plus#properties
// properties: https://github.com/stevegreatrex/ko.plus#properties
//
isRunning: KnockoutObservable<boolean>;
@ -89,7 +84,7 @@ declare module KoPlus {
completed: KnockoutObservable<boolean>;
//
// functions
// functions
// see https://github.com/stevegreatrex/ko.plus#functions
//
done: (callback: (data: any) => void) => Command;
@ -99,7 +94,6 @@ declare module KoPlus {
always: (callback: Callback) => Command;
then: (resolve: Callback, reject: Callback) => Command;
}
//
@ -107,7 +101,6 @@ declare module KoPlus {
// see https://github.com/stevegreatrex/ko.plus#options
//
export interface CommandOptions {
// [required] sets the command action method
action: Callback;
@ -122,22 +115,23 @@ declare module KoPlus {
//#region Editable types
export interface EditableArrayStatic {
fn: KnockoutObservableArrayFunctions<any>;
<T>(value?: Array<T>): EditableArray<T>;
}
export interface EditableStatic {
fn: KnockoutObservableFunctions<any>;
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 EditableBase<T> extends KnockoutObservableFunctions<T> {
export interface EditableFunctions {
isEditing: KnockoutObservable<boolean>;
beginEdit(): void;
endEdit(): void;
@ -145,23 +139,17 @@ declare module KoPlus {
rollback(): void;
}
export interface Editable<T> extends EditableBase<T> {
(): T;
(value: T): void;
subscribe(callback: (newValue: T) => void, target?: any, topic?: string): KnockoutSubscription;
notifySubscribers(valueToWrite: T, topic?: string): void;
//
// extend the standard KnockoutObservable to add editable functions
//
export interface Editable<T> extends KnockoutObservable<T>, EditableFunctions {
}
export interface EditableArray<T> extends KnockoutObservableArrayFunctions<T>, EditableBase<T> {
(): T[];
(value: T[]): void;
subscribe(callback: (newValue: T[]) => void, target?: any, topic?: string): KnockoutSubscription;
notifySubscribers(valueToWrite: T[], topic?: string): void;
//
// extend the standard KnockoutObservableArray to add editable functions
//
export interface EditableArray<T> extends KnockoutObservableArray<T>, EditableFunctions {
}
//#endregion
}