Skip to content

Commit

Permalink
chore: InMemoryEntityInSetMixin types
Browse files Browse the repository at this point in the history
  • Loading branch information
k0stik committed Nov 27, 2024
1 parent 2cf3ebc commit 8fba18f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
3 changes: 3 additions & 0 deletions dist/js/entity/set/mixins.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { SystemInSetSchema } from "@mat3ra/esse/dist/js/types";
import { InMemoryEntityConstructor } from "../in_memory";
export type SystemInSet = Required<SystemInSetSchema>;
export type InSet = SystemInSet["inSet"][0];
export declare function InMemoryEntityInSetMixin<T extends InMemoryEntityConstructor>(superclass: T): {
new (...args: any[]): {
inSet: {
Expand Down
3 changes: 1 addition & 2 deletions dist/js/entity/set/mixins.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ exports.InMemoryEntityInSetMixin = InMemoryEntityInSetMixin;
function InMemoryEntitySetMixin(superclass) {
return class InMemoryEntitySetMixin extends superclass {
containsEntity(entity) {
var _a;
return (_a = entity === null || entity === void 0 ? void 0 : entity.inSet) === null || _a === void 0 ? void 0 : _a.some((ref) => ref._id === this.id);
return entity === null || entity === void 0 ? void 0 : entity.inSet.some((ref) => ref._id === this.id);
}
};
}
Expand Down
15 changes: 8 additions & 7 deletions src/js/entity/set/mixins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import { SystemInSetSchema } from "@mat3ra/esse/dist/js/types";

import { InMemoryEntityConstructor } from "../in_memory";

type SystemInSet = Required<SystemInSetSchema>;
export type SystemInSet = Required<SystemInSetSchema>;
export type InSet = SystemInSet["inSet"][0];

export function InMemoryEntityInSetMixin<T extends InMemoryEntityConstructor>(superclass: T) {
return class InMemoryEntityInSetMixin extends superclass implements SystemInSet {
get inSet() {
return this.prop("inSet", []);
return this.prop<InSet[]>("inSet", []);
}

set inSet(inSet: SystemInSet["inSet"]) {
set inSet(inSet: InSet[]) {
this.setProp("inSet", inSet);
}

Expand All @@ -26,12 +27,12 @@ export function InMemoryEntityInSetMixin<T extends InMemoryEntityConstructor>(su
};
}

type BaseEntityInSet = InstanceType<ReturnType<typeof InMemoryEntityInSetMixin>>;

export function InMemoryEntitySetMixin<T extends InMemoryEntityConstructor>(superclass: T) {
return class InMemoryEntitySetMixin extends superclass {
containsEntity<T extends InstanceType<ReturnType<typeof InMemoryEntityInSetMixin>>>(
entity?: T,
) {
return entity?.inSet?.some((ref) => ref._id === this.id);
containsEntity<T extends BaseEntityInSet>(entity?: T) {
return entity?.inSet.some((ref) => ref._id === this.id);
}
};
}

0 comments on commit 8fba18f

Please sign in to comment.