We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Currently all the mappers have the following form:
export interface FooJson extends BaseJson { ...props } export default class FooToJsonMapper extends BaseToJsonMapper { override mapFrom(target: FooJson): Foo { const version = target.serializationVersion ?? '{undefined}'; if (version.startsWith('0.3.')) return new Foo(target); //... additional versions throw new Error(`Unsupported serialization version: ${version}`); } override mapTo(source: Foo): FooJson { return { ...super.mapTo(source), // ..additionalProps }; } }
Most repositories are of the form:
export default class FooRepository extends BaseRepository<Foo> { constructor() { super('foo', new FooToJsonMapper(pkg.version)); } }
There is also a LocalStorageRepository specialized for the storage type:
LocalStorageRepository
export class LocalStorageRepository<E extends Entity> extends Repository<E> { constructor(readonly storageKey: string, mapper: Mapper<E, EntityJson>) { super(mapper); } get storage(): Storage { return localStorage; } get(id: E['id']): Promise<E | undefined> { ... } getAll(filter: (entity: E) => boolean = _ => true): Promise<E[]> { ... } add(item: E): Promise<void> { ... } clear(): Promise<void> { ... } update(item: E): Promise<void> { ... } delete(id: E['id']): Promise<void> { ... } }
Note the storage member which was defined to support unit testing:
storage
const fakeStorage: Storage = new DomStorage(null, { strict: true }); class TestLocalStorageRepository<F extends Foo> extends LocalStorageRepository<F> { override get storage() { return fakeStorage; } }
This smells and has significant duplication. This needs to be done better
The text was updated successfully, but these errors were encountered:
mlhaufe
Successfully merging a pull request may close this issue.
Currently all the mappers have the following form:
Most repositories are of the form:
There is also a
LocalStorageRepository
specialized for the storage type:Note the
storage
member which was defined to support unit testing:This smells and has significant duplication. This needs to be done better
The text was updated successfully, but these errors were encountered: