Skip to content

Commit

Permalink
map
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Kogut committed Jan 25, 2017
1 parent 185cc13 commit 62b1bb1
Show file tree
Hide file tree
Showing 8 changed files with 249 additions and 158 deletions.
4 changes: 2 additions & 2 deletions src/api/intercept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {getAdministration} from "../types/type-utils";

export function intercept<T>(value: IObservableValue<T>, handler: IInterceptor<IValueWillChange<T>>): Lambda;
export function intercept<T>(observableArray: IObservableArray<T>, handler: IInterceptor<IArrayWillChange<T> | IArrayWillSplice<T>>): Lambda;
export function intercept<T>(observableMap: ObservableMap<T>, handler: IInterceptor<IMapWillChange<T>>): Lambda;
export function intercept<T>(observableMap: ObservableMap<T>, property: string, handler: IInterceptor<IValueWillChange<T>>): Lambda;
export function intercept<K, T>(observableMap: ObservableMap<K, T>, handler: IInterceptor<IMapWillChange<K, T>>): Lambda;
export function intercept<K, T>(observableMap: ObservableMap<K, T>, property: string, handler: IInterceptor<IValueWillChange<T>>): Lambda;
export function intercept(object: Object, handler: IInterceptor<IObjectWillChange>): Lambda;
export function intercept(object: Object, property: string, handler: IInterceptor<IValueWillChange<any>>): Lambda;
export function intercept(thing, propOrHandler?, handler?): Lambda {
Expand Down
16 changes: 8 additions & 8 deletions src/api/observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export interface IObservableFactory {
<T>(value: null | undefined): IObservableValue<T>;
(value: null | undefined): IObservableValue<any>;
(): IObservableValue<any>;
<T>(value: IMap<string | number | boolean, T>): ObservableMap<T>;
<K, T>(value: IMap<K, T>): ObservableMap<K, T>;
<T extends Object>(value: T): T & IObservableObject;
<T>(value: T): IObservableValue<T>;
}
Expand Down Expand Up @@ -86,16 +86,16 @@ export class IObservableFactories {
return new ObservableArray(initialValues, referenceEnhancer, name) as any;
}

map<T>(initialValues?: IObservableMapInitialValues<T>, name?: string): ObservableMap<T> {
map<K, T>(initialValues?: IObservableMapInitialValues<K, T>, name?: string): ObservableMap<K, T> {
if (arguments.length > 2)
incorrectlyUsedAsDecorator("map");
return new ObservableMap(initialValues, deepEnhancer, name);
return new ObservableMap<K, T>(initialValues, deepEnhancer, name);
}

shallowMap<T>(initialValues?: IObservableMapInitialValues<T>, name?: string): ObservableMap<T> {
shallowMap<K, T>(initialValues?: IObservableMapInitialValues<K, T>, name?: string): ObservableMap<K, T> {
if (arguments.length > 2)
incorrectlyUsedAsDecorator("shallowMap");
return new ObservableMap(initialValues, referenceEnhancer, name);
return new ObservableMap<K, T>(initialValues, referenceEnhancer, name);
}

object<T>(props: T, name?: string): T & IObservableObject {
Expand Down Expand Up @@ -140,7 +140,7 @@ export class IObservableFactories {
*/
shallow(target: Object, property: string, descriptor?: PropertyDescriptor): any;
shallow<T>(initialValues: T[]): IObservableArray<T>;
shallow<T>(initialValues: IMap<string | number | boolean, T>): ObservableMap<T>;
shallow<K, T>(initialValues: IMap<K, T>): ObservableMap<K, T>;
shallow<T extends Object>(value: T): T;
shallow() {
if (arguments.length < 2) {
Expand All @@ -154,7 +154,7 @@ export class IObservableFactories {

deep(target: Object, property: string, descriptor?: PropertyDescriptor): any;
deep<T>(initialValues: T[]): IObservableArray<T>;
deep<T>(initialValues: IMap<string | number | boolean, T>): ObservableMap<T>;
deep<K, T>(initialValues: IMap<K, T>): ObservableMap<K, T>;
deep<T>(initialValue: T): T;
deep() {
if (arguments.length < 2) {
Expand All @@ -168,7 +168,7 @@ export class IObservableFactories {

struct(target: Object, property: string, descriptor?: PropertyDescriptor): any;
struct<T>(initialValues: T[]): IObservableArray<T>;
struct<T>(initialValues: IMap<string | number | boolean, T>): ObservableMap<T>;
struct<K, T>(initialValues: IMap<K, T>): ObservableMap<K, T>;
struct<T>(initialValue: T): T;
struct() {
if (arguments.length < 2) {
Expand Down
4 changes: 2 additions & 2 deletions src/api/observe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {getAdministration} from "../types/type-utils";

export function observe<T>(value: IObservableValue<T> | IComputedValue<T>, listener: (change: IValueDidChange<T>) => void, fireImmediately?: boolean): Lambda;
export function observe<T>(observableArray: IObservableArray<T>, listener: (change: IArrayChange<T> | IArraySplice<T>) => void, fireImmediately?: boolean): Lambda;
export function observe<T>(observableMap: ObservableMap<T>, listener: (change: IMapChange<T>) => void, fireImmediately?: boolean): Lambda;
export function observe<T>(observableMap: ObservableMap<T>, property: string, listener: (change: IValueDidChange<T>) => void, fireImmediately?: boolean): Lambda;
export function observe<K, T>(observableMap: ObservableMap<K, T>, listener: (change: IMapChange<K, T>) => void, fireImmediately?: boolean): Lambda;
export function observe<K, T>(observableMap: ObservableMap<K, T>, property: string, listener: (change: IValueDidChange<T>) => void, fireImmediately?: boolean): Lambda;
export function observe(object: Object, listener: (change: IObjectChange) => void, fireImmediately?: boolean): Lambda;
export function observe(object: Object, property: string, listener: (change: IValueDidChange<any>) => void, fireImmediately?: boolean): Lambda;
export function observe(thing, propOrCb?, cbOrFire?, fireImmediately?): Lambda {
Expand Down
11 changes: 6 additions & 5 deletions src/types/modifiers-old.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ export function asFlat<T>(value: T): T {
return observable.shallow(value);
}

export function asMap(): ObservableMap<any>;
export function asMap<T>(): ObservableMap<T>;
export function asMap<T>(entries: IMapEntries<T>): ObservableMap<T>;
export function asMap<T>(data: IKeyValueMap<T>): ObservableMap<T>;
export function asMap(data?): ObservableMap<any> {
export function asMap(): ObservableMap<any, any>;
export function asMap<K, T>(): ObservableMap<K, T>;
export function asMap<K, T>(entries: IMapEntries<K, T>): ObservableMap<K, T>;
// FIXME
export function asMap<K, T>(data: IKeyValueMap<T>): ObservableMap<K, T>;
export function asMap(data?): ObservableMap<any, any> {
deprecated("asMap is deprecated, use observable.map or observable.shallowMap instead");
return observable.map(data || {});
}
Loading

0 comments on commit 62b1bb1

Please sign in to comment.