diff --git a/mendixmodelsdk/index.d.ts b/mendixmodelsdk/index.d.ts index 29192f4bc4..d75cdb97aa 100644 --- a/mendixmodelsdk/index.d.ts +++ b/mendixmodelsdk/index.d.ts @@ -207,8 +207,188 @@ limitations under the License. */ +// Outdated mobservable typings. +// TODO: Use the types bundled with mobservable. Or use mobx. + +interface _IMobservableStatic { + /** + * Turns an object, array or function into a reactive structure. + * @param value the value which should become observable. + */ + makeReactive: IMakeReactive; + + /** + * Extends an object with reactive capabilities. + * @param target the object to which reactive properties should be added + * @param properties the properties that should be added and made reactive + * @returns targer + */ + extendReactive(target: Object, properties: Object):Object; + + /** + * Returns true if the provided value is reactive. + * @param value object, function or array + * @param propertyName if propertyName is specified, checkes whether value.propertyName is reactive. + */ + isReactive(value: any, propertyName?:string): boolean; + + /** + * Can be used in combination with makeReactive / extendReactive. + * Enforces that a reference to 'value' is stored as property, + * but that 'value' itself is not turned into something reactive. + * Future assignments to the same property will inherit this behavior. + * @param value initial value of the reactive property that is being defined. + */ + asReference(value: any):{value:T}; + + /** + * ES6 / Typescript decorator which can to make class properties and getter functions reactive. + */ + observable(target: Object, key: string):any; // decorator / annotation + + /** + * Creates a reactive view and keeps it alive, so that the view is always + * updated if one of the dependencies changes, even when the view is not further used by something else. + * @param func The reactive view + * @param scope (optional) + * @returns disposer function, which can be used to stop the view from being updated in the future. + */ + observe(func: Mobservable.Lambda, scope?: any): Mobservable.Lambda; + + /** + * Deprecated, use mobservable.observe instead. + */ + sideEffect(func: Mobservable.Lambda, scope?: any): Mobservable.Lambda; + + /** + * Similar to 'observer', observes the given predicate until it returns true. + * Once it returns true, the 'effect' function is invoked an the observation is cancelled. + * @param predicate + * @param effect + * @param scope (optional) + * @returns disposer function to prematurely end the observer. + */ + observeUntil(predicate: ()=>boolean, effect: Mobservable.Lambda, scope?: any): Mobservable.Lambda; + + /** + * During a transaction no views are updated until the end of the transaction. + * The transaction will be run synchronously nonetheless. + * @param action a function that updates some reactive state + * @returns any value that was returned by the 'action' parameter. + */ + transaction(action: ()=>T): T; + + /** + * Converts a reactive structure into a non-reactive structure. + * Basically a deep-clone. + */ + toJSON(value: T): T; + + /** + * Sets the reporting level Defaults to 1. Use 0 for production or 2 for increased verbosity. + */ + logLevel: number; // 0 = production, 1 = development, 2 = debugging + + extras: { + getDependencyTree(thing:any, property?:string): Mobservable.IDependencyTree; + + getObserverTree(thing:any, property?:string): Mobservable.IObserverTree; + + trackTransitions(extensive?:boolean, onReport?:(lines:Mobservable.ITransitionEvent) => void) : Mobservable.Lambda; + } +} + +interface IMakeReactive { + (value: T[], opts?: Mobservable.IMakeReactiveOptions): Mobservable.IObservableArray; + (value: ()=>T, opts?: Mobservable.IMakeReactiveOptions): Mobservable.IObservableValue; + (value: T, opts?: Mobservable.IMakeReactiveOptions): Mobservable.IObservableValue; + (value: Object, opts?: Mobservable.IMakeReactiveOptions): T; +} + +interface IMobservableStatic extends _IMobservableStatic, IMakeReactive { +} + +declare namespace Mobservable { + interface IMakeReactiveOptions { + as?: string /* "auto" | "reference" | TODO: see #8 "structure" */ + scope?: Object, + context?: Object, + recurse?: boolean; + name?: string; + // protected: boolean TODO: see #9 + } + + export interface IContextInfoStruct { + object: Object; + name: string; + } + + export type IContextInfo = IContextInfoStruct | string; + + interface Lambda { + (): void; + name?: string; + } + + interface IObservable { + observe(callback: (...args: any[])=>void, fireImmediately?: boolean): Lambda; + } + + interface IObservableValue extends IObservable { + (): T; + (value: T):void; + observe(callback: (newValue: T, oldValue: T)=>void, fireImmediately?: boolean): Lambda; + } + + interface IObservableArray extends IObservable, Array { + spliceWithArray(index: number, deleteCount?: number, newItems?: T[]): T[]; + observe(listener: (changeData: IArrayChange|IArraySplice)=>void, fireImmediately?: boolean): Lambda; + clear(): T[]; + replace(newItems: T[]): T[]; + find(predicate: (item: T,index: number,array: IObservableArray)=>boolean,thisArg?: any,fromIndex?: number): T; + remove(value: T): boolean; + } + + interface IArrayChange { + type: string; // Always: 'update' + object: IObservableArray; + index: number; + oldValue: T; + } + + interface IArraySplice { + type: string; // Always: 'splice' + object: IObservableArray; + index: number; + removed: T[]; + addedCount: number; + } + + interface IDependencyTree { + id: number; + name: string; + context: any; + dependencies?: IDependencyTree[]; + } + + interface IObserverTree { + id: number; + name: string; + context: any; + observers?: IObserverTree[]; + listeners?: number; // amount of functions manually attached using an .observe method + } + + interface ITransitionEvent { + id: number; + name: string; + context: Object; + state: string; + changed: boolean; + newValue: string; + } +} -/// declare module "mendixmodelsdk" { namespace sdk { namespace internal { diff --git a/mobservable/index.d.ts b/mobservable/index.d.ts deleted file mode 100644 index 719eddaf31..0000000000 --- a/mobservable/index.d.ts +++ /dev/null @@ -1,178 +0,0 @@ -// Type definitions for mobservable 0.6 -// Project: https://mweststrate.github.io/mobservable -// Definitions by: Michel Weststrate -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -declare namespace Mobservable { - interface Static extends MakeReactive { - /** - * Turns an object, array or function into a reactive structure. - * @param value the value which should become observable. - */ - makeReactive: MakeReactive; - - /** - * Extends an object with reactive capabilities. - * @param target the object to which reactive properties should be added - * @param properties the properties that should be added and made reactive - * @returns targer - */ - extendReactive(target: Object, properties: Object): Object; - - /** - * Returns true if the provided value is reactive. - * @param value object, function or array - * @param propertyName if propertyName is specified, checkes whether value.propertyName is reactive. - */ - isReactive(value: any, propertyName?: string): boolean; - - /** - * Can be used in combination with makeReactive / extendReactive. - * Enforces that a reference to 'value' is stored as property, - * but that 'value' itself is not turned into something reactive. - * Future assignments to the same property will inherit this behavior. - * @param value initial value of the reactive property that is being defined. - */ - asReference(value: any): {value: T}; - - /** - * ES6 / Typescript decorator which can to make class properties and getter functions reactive. - */ - observable(target: Object, key: string): any; // decorator / annotation - - /** - * Creates a reactive view and keeps it alive, so that the view is always - * updated if one of the dependencies changes, even when the view is not further used by something else. - * @param func The reactive view - * @param scope (optional) - * @returns disposer function, which can be used to stop the view from being updated in the future. - */ - observe(func: Mobservable.Lambda, scope?: any): Mobservable.Lambda; - - /** - * Deprecated, use mobservable.observe instead. - */ - sideEffect(func: Mobservable.Lambda, scope?: any): Mobservable.Lambda; - - /** - * Similar to 'observer', observes the given predicate until it returns true. - * Once it returns true, the 'effect' function is invoked an the observation is cancelled. - * @param predicate - * @param effect - * @param scope (optional) - * @returns disposer function to prematurely end the observer. - */ - observeUntil(predicate: () => boolean, effect: Mobservable.Lambda, scope?: any): Mobservable.Lambda; - - /** - * During a transaction no views are updated until the end of the transaction. - * The transaction will be run synchronously nonetheless. - * @param action a function that updates some reactive state - * @returns any value that was returned by the 'action' parameter. - */ - transaction(action: () => T): T; - - /** - * Converts a reactive structure into a non-reactive structure. - * Basically a deep-clone. - */ - toJSON(value: T): T; - - /** - * Sets the reporting level Defaults to 1. Use 0 for production or 2 for increased verbosity. - */ - logLevel: number; // 0 = production, 1 = development, 2 = debugging - - extras: { - getDependencyTree(thing: any, property?: string): Mobservable.DependencyTree; - - getObserverTree(thing: any, property?: string): Mobservable.ObserverTree; - - trackTransitions(extensive?: boolean, onReport?: (lines: Mobservable.TransitionEvent) => void): Mobservable.Lambda; - }; - } - - interface MakeReactive { - (value: T[], opts?: Mobservable.MakeReactiveOptions): Mobservable.ObservableArray; - (value: () => T, opts?: Mobservable.MakeReactiveOptions): Mobservable.ObservableValue; - (value: T, opts?: Mobservable.MakeReactiveOptions): Mobservable.ObservableValue; - (value: Object, opts?: Mobservable.MakeReactiveOptions): T; - } - - interface MakeReactiveOptions { - as?: string; /* "auto" | "reference" | TODO: see #8 "structure" */ - scope?: Object; - context?: Object; - recurse?: boolean; - name?: string; - // protected: boolean TODO: see #9 - } - - type ContextInfo = { object: Object; name: string } | string; - - interface Lambda { - (): void; - name?: string; - } - - interface Observable { - observe(callback: (...args: any[]) => void, fireImmediately?: boolean): Lambda; - } - - interface ObservableValue extends Observable { - (): T; - (value: T): void; - observe(callback: (newValue: T, oldValue: T) => void, fireImmediately?: boolean): Lambda; - } - - interface ObservableArray extends Observable, Array { - spliceWithArray(index: number, deleteCount?: number, newItems?: T[]): T[]; - observe(listener: (changeData: ArrayChange|ArraySplice) => void, fireImmediately?: boolean): Lambda; - clear(): T[]; - replace(newItems: T[]): T[]; - find(predicate: (item: T, index: number, array: ObservableArray) => boolean, thisArg?: any, fromIndex?: number): T; - remove(value: T): boolean; - } - - interface ArrayChange { - type: string; // Always: 'update' - object: ObservableArray; - index: number; - oldValue: T; - } - - interface ArraySplice { - type: string; // Always: 'splice' - object: ObservableArray; - index: number; - removed: T[]; - addedCount: number; - } - - interface DependencyTree { - id: number; - name: string; - context: any; - dependencies?: DependencyTree[]; - } - - interface ObserverTree { - id: number; - name: string; - context: any; - observers?: ObserverTree[]; - listeners?: number; // amount of functions manually attached using an .observe method - } - - interface TransitionEvent { - id: number; - name: string; - context: Object; - state: string; - changed: boolean; - newValue: string; - } -} - -declare const Mobservable: Mobservable.Static; -export = Mobservable; diff --git a/mobservable/mobservable-tests.ts b/mobservable/mobservable-tests.ts deleted file mode 100644 index 060f0d14b3..0000000000 --- a/mobservable/mobservable-tests.ts +++ /dev/null @@ -1,56 +0,0 @@ -import mobservable = require('mobservable'); -import {observable} from "mobservable"; - -var v = mobservable(3); -v.observe(() => {}); - -var a = mobservable([1, 2, 3]); - -class Order { - @observable price: number = 3; - @observable amount: number = 2; - @observable orders: string[] = []; - - @observable get total() { - return this.amount * this.price * (1 + this.orders.length); - } -} - -export function testObservable() { - var a = mobservable(3); - var b = mobservable(() => a() * 2); -} - -export function testAnnotations() { - var order1totals: number[] = []; - var order1 = new Order(); - var order2 = new Order(); - - var disposer = mobservable.observe(() => { - order1totals.push(order1.total); - }); - - order2.price = 4; - order1.amount = 1; - - order2.orders.push('bla'); - - order1.orders.splice(0, 0, 'boe', 'hoi'); - - disposer(); - order1.orders.pop(); -}; - -export function testTyping() { - var ar: mobservable.ObservableArray = mobservable.makeReactive([1, 2]); - ar.observe((d: mobservable.ArrayChange | mobservable.ArraySplice) => { - console.log(d.type); - }); - - var ar2: mobservable.ObservableArray = mobservable([1, 2]); - ar2.observe((d: mobservable.ArrayChange | mobservable.ArraySplice) => { - console.log(d.type); - }); - - var x: mobservable.ObservableValue = mobservable(3); -} \ No newline at end of file diff --git a/mobservable/tsconfig.json b/mobservable/tsconfig.json deleted file mode 100644 index cee6db4b01..0000000000 --- a/mobservable/tsconfig.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "target": "es6", - "lib": [ - "es6", - "dom" - ], - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": false, - "baseUrl": "../", - "experimentalDecorators": true, - "typeRoots": [ - "../" - ], - "types": [], - "noEmit": true, - "forceConsistentCasingInFileNames": true - }, - "files": [ - "index.d.ts", - "mobservable-tests.ts" - ] -} \ No newline at end of file diff --git a/mobservable/tslint.json b/mobservable/tslint.json deleted file mode 100644 index f05741c59b..0000000000 --- a/mobservable/tslint.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": "../tslint.json", - "rules": { - "forbidden-types": false - } -} diff --git a/notNeededPackages.json b/notNeededPackages.json index fce0ef50f0..f0619f8e79 100644 --- a/notNeededPackages.json +++ b/notNeededPackages.json @@ -329,6 +329,12 @@ "typingsPackageName": "fine-uploader", "sourceRepoURL": "http://fineuploader.com/", "asOfVersion": "5.14.0" + }, + { + "libraryName": "mobservable", + "typingsPackageName": "mobservable", + "sourceRepoURL": "github.com/mweststrate/mobservable", + "asOfVersion": "1.2.5" } ] } \ No newline at end of file