Comparing version 1.0.40 to 1.0.41
@@ -40,3 +40,3 @@ { | ||
"typings": "src/lanurite.d.ts", | ||
"version": "1.0.40", | ||
"version": "1.0.41", | ||
"license": "MIT", | ||
@@ -43,0 +43,0 @@ "repository": { |
/// <reference types="lodash" /> | ||
import * as _ from "lodash"; | ||
import { Dictionary } from "lodash"; | ||
import { ICollection } from "../interfaces/ICollection"; | ||
import { IModel } from "../interfaces/IModel"; | ||
import { Event } from "./Event"; | ||
declare class Collection<T extends IModel> extends Event implements ICollection<T> { | ||
import { Model } from "./Model"; | ||
declare class Collection<T extends Model> extends Event implements ICollection<T> { | ||
private _models; | ||
@@ -17,3 +18,3 @@ constructor(array?: Array<T>); | ||
*/ | ||
add(model: IModel): boolean; | ||
add(model: T | IModel): boolean; | ||
/** | ||
@@ -24,3 +25,3 @@ * Remove model from collection, return true if model removed or False if model not in collection | ||
*/ | ||
remove(model: IModel): boolean; | ||
remove(model: T): boolean; | ||
/** | ||
@@ -31,3 +32,3 @@ * Return existing model in collection | ||
*/ | ||
has(model: IModel): boolean; | ||
has(model: T): boolean; | ||
/** | ||
@@ -98,3 +99,3 @@ * Clear collection, remove all models, event will be save | ||
*/ | ||
toJSON(): T[]; | ||
toJSON(): any; | ||
/** | ||
@@ -122,3 +123,3 @@ * Sorting collection with predicate, changing collection order. | ||
*/ | ||
countBy(predicate: any): _.Dictionary<number>; | ||
countBy(predicate: any): Dictionary<number>; | ||
/** | ||
@@ -130,3 +131,3 @@ * Creates an object composed of keys generated from the results of running each element of collection thru iteratee. The order of grouped values is determined by the | ||
*/ | ||
groupBy(predicate: any): _.Dictionary<T[]>; | ||
groupBy(predicate: any): Dictionary<Array<T>>; | ||
/** | ||
@@ -133,0 +134,0 @@ * Destoy Collection remove all event and trigger destroy |
import * as _ from "lodash" | ||
import {Dictionary} from "lodash" | ||
import {ICollection} from "../interfaces/ICollection" | ||
@@ -7,3 +8,3 @@ import {IModel} from "../interfaces/IModel" | ||
class Collection<T extends IModel> extends Event implements ICollection<T> { | ||
class Collection<T extends Model> extends Event implements ICollection<T> { | ||
@@ -43,3 +44,3 @@ private _models: any = {} | ||
public add(model: IModel) { | ||
public add(model: T | IModel) { | ||
if (_.isUndefined(this._models[model.get("l_id")])) { | ||
@@ -59,3 +60,3 @@ this._models[model.get("l_id")] = model | ||
public remove(model: IModel) { | ||
public remove(model: T) { | ||
if (!_.isUndefined(this._models[model.get("l_id")])) { | ||
@@ -75,3 +76,3 @@ delete this._models[model.get("l_id")] | ||
public has(model: IModel) { | ||
public has(model: T) { | ||
return !_.isUndefined(this._models[model.get("l_id")]) | ||
@@ -206,3 +207,3 @@ } | ||
public toJSON() { | ||
public toJSON(): any { | ||
return this.map((el) => { | ||
@@ -218,3 +219,3 @@ return el.toJSON() | ||
public sortBy(predicate: any) { | ||
public sortBy(predicate: any): void { | ||
this.reset(this.getAll().sort(predicate)) | ||
@@ -247,3 +248,3 @@ } | ||
public countBy(predicate: any) { | ||
public countBy(predicate: any): Dictionary<number> { | ||
return _.countBy(this.getAll(), predicate) | ||
@@ -258,3 +259,3 @@ } | ||
*/ | ||
public groupBy(predicate: any) { | ||
public groupBy(predicate: any): Dictionary<Array<T>> { | ||
return _.groupBy(this.getAll(), predicate) | ||
@@ -261,0 +262,0 @@ } |
@@ -0,7 +1,9 @@ | ||
/// <reference types="lodash" /> | ||
import { Dictionary } from "lodash"; | ||
import { IModel } from "./IModel"; | ||
export interface ICollection<T extends IModel> { | ||
add(model: IModel): boolean; | ||
remove(model: IModel): boolean; | ||
add(model: T | IModel): boolean; | ||
remove(model: T): boolean; | ||
clear(): void; | ||
has(model: IModel): boolean; | ||
has(model: T): boolean; | ||
getAll(): Array<T>; | ||
@@ -12,3 +14,3 @@ merge(collection: Array<T> | ICollection<T>): void; | ||
reduce(predicate: any, accum: any): any; | ||
getById(id: string): IModel | null; | ||
getById(id: string): T | null; | ||
find(predicate: any, start: number): T | undefined; | ||
@@ -19,8 +21,8 @@ reset(array: Array<T>): void; | ||
toJSON(): any; | ||
sortBy(predicate: any): any; | ||
sortBy(predicate: any): void; | ||
toArray(): Array<T>; | ||
chunk(size: number): Array<Array<T>>; | ||
countBy(predicate: any): any; | ||
groupBy(predicate: any): any; | ||
countBy(predicate: any): Dictionary<number>; | ||
groupBy(predicate: any): Dictionary<Array<T>>; | ||
destroy(): void; | ||
} |
@@ -0,8 +1,10 @@ | ||
import {Dictionary} from "lodash" | ||
import {IEvent} from "./IEvent" | ||
import {IModel} from "./IModel" | ||
export interface ICollection<T extends IModel> { | ||
add(model: IModel): boolean | ||
remove(model: IModel): boolean | ||
add(model: T | IModel): boolean | ||
remove(model: T): boolean | ||
clear(): void | ||
has(model: IModel): boolean | ||
has(model: T): boolean | ||
getAll(): Array<T> | ||
@@ -13,3 +15,3 @@ merge(collection: Array<T> | ICollection<T>): void | ||
reduce(predicate: any, accum: any): any | ||
getById(id: string): IModel | null | ||
getById(id: string): T | null | ||
find(predicate: any, start: number): T | undefined | ||
@@ -20,8 +22,8 @@ reset(array: Array<T>): void | ||
toJSON(): any | ||
sortBy(predicate: any): any | ||
sortBy(predicate: any): void | ||
toArray(): Array<T> | ||
chunk(size: number): Array<Array<T>> | ||
countBy(predicate: any): any | ||
groupBy(predicate: any): any | ||
countBy(predicate: any): Dictionary<number> | ||
groupBy(predicate: any): Dictionary<Array<T>> | ||
destroy(): void | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
827811
5469