Skip to content

Commit

Permalink
Merge 42bc2df into 51f8f1c
Browse files Browse the repository at this point in the history
  • Loading branch information
Enteee committed Jul 23, 2020
2 parents 51f8f1c + 42bc2df commit 7986450
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config.xml
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<widget id="ch.duckpond.count" version="0.0.5" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<widget id="ch.duckpond.count" version="0.0.6" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Count</name>
<description>Count, Visualize, Understand</description>
<author email="count@duckpond.ch" href="https://duckpond.ch">Ente</author>
Expand Down
13 changes: 13 additions & 0 deletions src/app/models/model-repository.service.spec.ts
Expand Up @@ -26,4 +26,17 @@ describe('ModelRepositoryService', () => {
).toBeRejectedWithError();
});

it('should throw error on MCtorName prefix collision', async () => {
await repositoryService.init({} as any, 'ABCD');
expectAsync(
repositoryService.init({} as any, 'ABC')
).toBeRejectedWithError();

await repositoryService.init({} as any, 'DEF');
expectAsync(
repositoryService.init({} as any, 'DEFG')
).toBeRejectedWithError();

});

});
14 changes: 13 additions & 1 deletion src/app/models/model-repository.service.ts
Expand Up @@ -38,8 +38,20 @@ export class ModelRepositoryService<M extends Model> implements Resolve<M> {
* ref: https://stackoverflow.com/questions/48438666/typescript-get-class-name-in-its-own-property-at-compile-time
*/
if (KnownMCtorNames.includes(MCtorName)){
throw new Error(`MCtorName not unique: ${MCtorName}`);
throw new Error(`MCtorName not unique: "${MCtorName}"`);
}

// we also have to make sure that no MCtorName is a prefix of another.
for (const otherMCtorName of KnownMCtorNames) {
if (otherMCtorName.startsWith(MCtorName)) {
throw new Error(`MCtorName "${MCtorName}" is a prefix of ${otherMCtorName}"`);
}

if (MCtorName.startsWith(otherMCtorName)) {
throw new Error(`MCtorName "${otherMCtorName}" is a prefix of ${MCtorName}"`);
}
}

KnownMCtorNames.push(MCtorName);

this.MCtor = MCtor;
Expand Down
2 changes: 1 addition & 1 deletion src/app/models/model.module.ts
Expand Up @@ -24,7 +24,7 @@ export function initializeModelServices(
appStateRepositoryService.init(AppState, 'AppState'),
analyticsItemRepositoryService.init(AnalyticsItem, 'AnalyticsItem'),
counterRepositoryService.init(Counter, 'Counter'),
countEventRepositoryService.init(CountEvent, 'CounterEvent'),
countEventRepositoryService.init(CountEvent, 'CounteEvent'),
]);
};
}
Expand Down

0 comments on commit 7986450

Please sign in to comment.