From 2a67c1e9235e065efb69d4a661844734bf32b0ab Mon Sep 17 00:00:00 2001 From: HowardRichards Date: Wed, 18 Feb 2015 11:19:52 +0000 Subject: [PATCH] Fixed bug - makeEditable now on .editable Also refactored how editable types inherit - now simpler --- ko.plus/ko.plus-tests.ts | 4 +++ ko.plus/ko.plus.d.ts | 58 ++++++++++++++++------------------------ 2 files changed, 27 insertions(+), 35 deletions(-) diff --git a/ko.plus/ko.plus-tests.ts b/ko.plus/ko.plus-tests.ts index 952b286d2..992332e2b 100644 --- a/ko.plus/ko.plus-tests.ts +++ b/ko.plus/ko.plus-tests.ts @@ -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(1); // with union types var edit5 = ko.editable("test"); + ko.editable.makeEditable(this); + // test getting the value var value = edit1(); diff --git a/ko.plus/ko.plus.d.ts b/ko.plus/ko.plus.d.ts index 734558d01..65301aa7c 100644 --- a/ko.plus/ko.plus.d.ts +++ b/ko.plus/ko.plus.d.ts @@ -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 { //#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; @@ -89,7 +84,7 @@ declare module KoPlus { completed: KnockoutObservable; // - // 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; - (value?: Array): EditableArray; - } - - export interface EditableStatic { - fn: KnockoutObservableFunctions; + export interface EditableStatic extends KnockoutObservableStatic { (value?: T): Editable; makeEditable(target: any): void; } + export interface EditableArrayStatic extends KnockoutObservableArrayStatic { + (value?: Array): EditableArray; + + makeEditable(target: any): void; //> + } + // // defines common editable functions and isEditing property + // (used by both editable and editableArray // - export interface EditableBase extends KnockoutObservableFunctions { + export interface EditableFunctions { isEditing: KnockoutObservable; beginEdit(): void; endEdit(): void; @@ -145,23 +139,17 @@ declare module KoPlus { rollback(): void; } - export interface Editable extends EditableBase { - (): 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 extends KnockoutObservable, EditableFunctions { } - export interface EditableArray extends KnockoutObservableArrayFunctions, EditableBase { - (): 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 extends KnockoutObservableArray, EditableFunctions { } - //#endregion - } \ No newline at end of file