Closed sbbowers closed 8 years ago
Any reason this PR not merged yet? Looks super useful.
¯(ツ)/¯ In the interim, I'm doing something like the following. I keep all of my storage in a DataStore class that I inject into other classes that need it. DataStore is responsible for constructing real models on top of the generic objects provided by LocalStorage. For now, generic JSON.stringify is working for me for serialization. ModelStore has all the logic to do lookup/insert/delete, etc.
export type ConstructorFunc<T> = { new(...args : any[]): T; }
export class ModelStore<modelType extends BaseModel> {
private data: Array<modelType> = [];
constructor(data: Array<modelType>, modelType: ConstructorFunc<modelType>) {
this.data = data;
this.data.forEach((e, i, d) => { d[i] = new modelType(e) });
}
}
export class DataStore {
@LocalStorage() private myModels: Array<MyModel> = [];
myModelStore: ModelStore<MyModel>;
constructor() {
this.myStore = new MyStore<MyModel>(this.myModels, MyModel);
}
}```
This library is almost not maintained anymore, pls see readme. However, I'm merging this for now as its really useful. Thanks!
This change provides support for complex datatypes that require a more complex serializer that JSON.stringify/parse
Decorator function signature now accepts named parameters via an object. Maintains backward compatibility with original function signature as well.
Example: