Skip to content

Commit 79e2e78

Browse files
committed
chore: cleanup mixins
1 parent 504737d commit 79e2e78

File tree

12 files changed

+55
-140
lines changed

12 files changed

+55
-140
lines changed

dist/js/entity/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ContextAndRenderFieldsMixin } from "./mixins/context";
33
import { RuntimeContextFieldMixin } from "./mixins/context_runtime";
44
import { FlowchartEntityMixin, FlowchartItemMixin } from "./mixins/flowchart";
55
import { HashedInputArrayMixin } from "./mixins/hash";
6-
import { HasDescriptionMixin, HasScopeTrackMixin, TaggableMixin } from "./mixins/props";
6+
import { HasScopeTrackMixin } from "./mixins/props";
77
import { RuntimeItemsMixin } from "./mixins/runtime_items";
88
import { DefaultableInMemoryEntity, HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity, HasMetadataNamedDefaultableInMemoryEntity, NamedDefaultableInMemoryEntity, NamedDefaultableRepetitionContextAndRenderInMemoryEntity, NamedDefaultableRepetitionImportantSettingsInMemoryEntity, NamedDefaultableRepetitionRuntimeItemsImportantSettingsContextAndRenderHashedInMemoryEntity, NamedInMemoryEntity } from "./other";
99
import { InMemoryEntitySet } from "./set";
@@ -12,4 +12,4 @@ import { constructEntitySetFactoryByConfig } from "./set/factory";
1212
import { InMemoryEntityInSetMixin, InMemoryEntitySetMixin } from "./set/mixins";
1313
import { OrderedInMemoryEntityInSetMixin, OrderedInMemoryEntitySetMixin } from "./set/ordered/mixins";
1414
import * as selectorsForEntitySet from "./set/selectors";
15-
export { InMemoryEntity, NamedInMemoryEntity, DefaultableInMemoryEntity, NamedDefaultableInMemoryEntity, HasMetadataNamedDefaultableInMemoryEntity, NamedDefaultableRepetitionContextAndRenderInMemoryEntity, NamedDefaultableRepetitionImportantSettingsInMemoryEntity, NamedDefaultableRepetitionRuntimeItemsImportantSettingsContextAndRenderHashedInMemoryEntity, HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity, HasDescriptionMixin, TaggableMixin, HasScopeTrackMixin, RuntimeItemsMixin, RuntimeContextFieldMixin, HashedInputArrayMixin, InMemoryEntitySet, ENTITY_SET_TYPES, constructEntitySetFactoryByConfig, selectorsForEntitySet, InMemoryEntitySetMixin, InMemoryEntityInSetMixin, OrderedInMemoryEntitySetMixin, OrderedInMemoryEntityInSetMixin, ContextAndRenderFieldsMixin, FlowchartEntityMixin, FlowchartItemMixin, };
15+
export { InMemoryEntity, NamedInMemoryEntity, DefaultableInMemoryEntity, NamedDefaultableInMemoryEntity, HasMetadataNamedDefaultableInMemoryEntity, NamedDefaultableRepetitionContextAndRenderInMemoryEntity, NamedDefaultableRepetitionImportantSettingsInMemoryEntity, NamedDefaultableRepetitionRuntimeItemsImportantSettingsContextAndRenderHashedInMemoryEntity, HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity, HasScopeTrackMixin, RuntimeItemsMixin, RuntimeContextFieldMixin, HashedInputArrayMixin, InMemoryEntitySet, ENTITY_SET_TYPES, constructEntitySetFactoryByConfig, selectorsForEntitySet, InMemoryEntitySetMixin, InMemoryEntityInSetMixin, OrderedInMemoryEntitySetMixin, OrderedInMemoryEntityInSetMixin, ContextAndRenderFieldsMixin, FlowchartEntityMixin, FlowchartItemMixin, };

dist/js/entity/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
3333
};
3434
})();
3535
Object.defineProperty(exports, "__esModule", { value: true });
36-
exports.FlowchartItemMixin = exports.FlowchartEntityMixin = exports.ContextAndRenderFieldsMixin = exports.OrderedInMemoryEntityInSetMixin = exports.OrderedInMemoryEntitySetMixin = exports.InMemoryEntityInSetMixin = exports.InMemoryEntitySetMixin = exports.selectorsForEntitySet = exports.constructEntitySetFactoryByConfig = exports.ENTITY_SET_TYPES = exports.InMemoryEntitySet = exports.HashedInputArrayMixin = exports.RuntimeContextFieldMixin = exports.RuntimeItemsMixin = exports.HasScopeTrackMixin = exports.TaggableMixin = exports.HasDescriptionMixin = exports.HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity = exports.NamedDefaultableRepetitionRuntimeItemsImportantSettingsContextAndRenderHashedInMemoryEntity = exports.NamedDefaultableRepetitionImportantSettingsInMemoryEntity = exports.NamedDefaultableRepetitionContextAndRenderInMemoryEntity = exports.HasMetadataNamedDefaultableInMemoryEntity = exports.NamedDefaultableInMemoryEntity = exports.DefaultableInMemoryEntity = exports.NamedInMemoryEntity = exports.InMemoryEntity = void 0;
36+
exports.FlowchartItemMixin = exports.FlowchartEntityMixin = exports.ContextAndRenderFieldsMixin = exports.OrderedInMemoryEntityInSetMixin = exports.OrderedInMemoryEntitySetMixin = exports.InMemoryEntityInSetMixin = exports.InMemoryEntitySetMixin = exports.selectorsForEntitySet = exports.constructEntitySetFactoryByConfig = exports.ENTITY_SET_TYPES = exports.InMemoryEntitySet = exports.HashedInputArrayMixin = exports.RuntimeContextFieldMixin = exports.RuntimeItemsMixin = exports.HasScopeTrackMixin = exports.HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity = exports.NamedDefaultableRepetitionRuntimeItemsImportantSettingsContextAndRenderHashedInMemoryEntity = exports.NamedDefaultableRepetitionImportantSettingsInMemoryEntity = exports.NamedDefaultableRepetitionContextAndRenderInMemoryEntity = exports.HasMetadataNamedDefaultableInMemoryEntity = exports.NamedDefaultableInMemoryEntity = exports.DefaultableInMemoryEntity = exports.NamedInMemoryEntity = exports.InMemoryEntity = void 0;
3737
const in_memory_1 = require("./in_memory");
3838
Object.defineProperty(exports, "InMemoryEntity", { enumerable: true, get: function () { return in_memory_1.InMemoryEntity; } });
3939
const context_1 = require("./mixins/context");
@@ -46,9 +46,7 @@ Object.defineProperty(exports, "FlowchartItemMixin", { enumerable: true, get: fu
4646
const hash_1 = require("./mixins/hash");
4747
Object.defineProperty(exports, "HashedInputArrayMixin", { enumerable: true, get: function () { return hash_1.HashedInputArrayMixin; } });
4848
const props_1 = require("./mixins/props");
49-
Object.defineProperty(exports, "HasDescriptionMixin", { enumerable: true, get: function () { return props_1.HasDescriptionMixin; } });
5049
Object.defineProperty(exports, "HasScopeTrackMixin", { enumerable: true, get: function () { return props_1.HasScopeTrackMixin; } });
51-
Object.defineProperty(exports, "TaggableMixin", { enumerable: true, get: function () { return props_1.TaggableMixin; } });
5250
const runtime_items_1 = require("./mixins/runtime_items");
5351
Object.defineProperty(exports, "RuntimeItemsMixin", { enumerable: true, get: function () { return runtime_items_1.RuntimeItemsMixin; } });
5452
const other_1 = require("./other");
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import type { DescriptionSchema } from "@mat3ra/esse/dist/js/types";
22
import type { Constructor } from "../../utils/types";
3-
import { InMemoryEntity, InMemoryEntityConstructor } from "../in_memory";
4-
export declare function hasDescriptionMixin(item: InMemoryEntity): {
3+
import { InMemoryEntity } from "../in_memory";
4+
export declare function hasDescriptionMixin<T extends InMemoryEntity>(item: T): InMemoryEntity & HasDescriptionInMemoryEntity;
5+
export type HasDescriptionInMemoryEntity = {
56
description: string;
67
descriptionObject: DescriptionSchema["descriptionObject"];
78
};
8-
export type HasDescriptionInMemoryEntity = ReturnType<typeof hasDescriptionMixin>;
99
export type HasDescriptionInMemoryEntityConstructor = Constructor<HasDescriptionInMemoryEntity>;
10-
export default function HasDescriptionMixin<S extends InMemoryEntityConstructor>(superclass: S): S & HasDescriptionInMemoryEntityConstructor;
Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,22 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
33
exports.hasDescriptionMixin = hasDescriptionMixin;
4-
exports.default = HasDescriptionMixin;
5-
function schemaMixin(item) {
6-
const schema = {
4+
function hasDescriptionMixin(item) {
5+
// @ts-expect-error
6+
const properties = {
77
get description() {
8-
return item.prop("description", "");
8+
return this.prop("description", "");
99
},
1010
set description(string) {
11-
item.setProp("description", string);
11+
this.setProp("description", string);
1212
},
1313
get descriptionObject() {
14-
return item.prop("descriptionObject");
14+
return this.prop("descriptionObject");
1515
},
1616
set descriptionObject(obj) {
17-
item.setProp("descriptionObject", obj);
17+
this.setProp("descriptionObject", obj);
1818
},
1919
};
20-
Object.defineProperties(item, Object.getOwnPropertyDescriptors(schema));
21-
return schema;
22-
}
23-
function hasDescriptionMixin(item) {
24-
return schemaMixin(item);
25-
}
26-
function HasDescriptionMixin(superclass) {
27-
class HasDescriptionMixin extends superclass {
28-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
29-
constructor(...args) {
30-
super(...args);
31-
hasDescriptionMixin(this);
32-
}
33-
}
34-
return HasDescriptionMixin;
20+
Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties));
21+
return properties;
3522
}
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import type { Constructor } from "../../utils/types";
2-
import type { InMemoryEntity, InMemoryEntityConstructor } from "../in_memory";
3-
export declare function taggableMixin(item: InMemoryEntity): {
4-
setTags(array: string[]): void;
2+
import { InMemoryEntity } from "../in_memory";
3+
export declare function taggableMixin<T extends InMemoryEntity>(item: T): InMemoryEntity & TaggableInMemoryEntity;
4+
export type TaggableInMemoryEntity = {
55
tags: string[];
6+
setTags: (array: string[]) => void;
67
};
7-
export type TaggableInMemoryEntity = ReturnType<typeof taggableMixin>;
88
export type TaggableInMemoryEntityConstructor = Constructor<TaggableInMemoryEntity>;
9-
export default function TaggableMixin<S extends InMemoryEntityConstructor>(superclass: S): S & TaggableInMemoryEntityConstructor;
Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,19 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
33
exports.taggableMixin = taggableMixin;
4-
exports.default = TaggableMixin;
5-
function schemaMixin(item) {
6-
const schema = {
4+
function taggableMixin(item) {
5+
// @ts-expect-error
6+
const properties = {
77
get tags() {
8-
return item.prop("tags", []);
8+
return this.prop("tags", []);
99
},
1010
set tags(array) {
11-
item.setProp("tags", array);
11+
this.setProp("tags", array);
1212
},
13-
};
14-
Object.defineProperties(item, Object.getOwnPropertyDescriptors(schema));
15-
return schema;
16-
}
17-
function propertiesMixin(item) {
18-
const properties = {
1913
setTags(array) {
20-
item.tags = array.filter((value, index, self) => self.indexOf(value) === index);
14+
this.tags = array.filter((value, index, self) => self.indexOf(value) === index);
2115
},
2216
};
2317
Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties));
2418
return properties;
2519
}
26-
function taggableMixin(item) {
27-
return {
28-
...schemaMixin(item),
29-
...propertiesMixin(item),
30-
};
31-
}
32-
function TaggableMixin(superclass) {
33-
class TaggableMixin extends superclass {
34-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
35-
constructor(...args) {
36-
super(...args);
37-
taggableMixin(this);
38-
}
39-
}
40-
return TaggableMixin;
41-
}

dist/js/entity/mixins/props.d.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
import HasDescriptionMixin from "./HasDescriptionMixin";
21
import HasScopeTrackMixin from "./HasScopeTrackMixin";
3-
import TaggableMixin from "./TaggableMixin";
4-
export { HasDescriptionMixin, HasScopeTrackMixin, TaggableMixin };
2+
export { HasScopeTrackMixin };

dist/js/entity/mixins/props.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
33
return (mod && mod.__esModule) ? mod : { "default": mod };
44
};
55
Object.defineProperty(exports, "__esModule", { value: true });
6-
exports.TaggableMixin = exports.HasScopeTrackMixin = exports.HasDescriptionMixin = void 0;
7-
const HasDescriptionMixin_1 = __importDefault(require("./HasDescriptionMixin"));
8-
exports.HasDescriptionMixin = HasDescriptionMixin_1.default;
6+
exports.HasScopeTrackMixin = void 0;
97
const HasScopeTrackMixin_1 = __importDefault(require("./HasScopeTrackMixin"));
108
exports.HasScopeTrackMixin = HasScopeTrackMixin_1.default;
11-
const TaggableMixin_1 = __importDefault(require("./TaggableMixin"));
12-
exports.TaggableMixin = TaggableMixin_1.default;

src/js/entity/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ContextAndRenderFieldsMixin } from "./mixins/context";
33
import { RuntimeContextFieldMixin } from "./mixins/context_runtime";
44
import { FlowchartEntityMixin, FlowchartItemMixin } from "./mixins/flowchart";
55
import { HashedInputArrayMixin } from "./mixins/hash";
6-
import { HasDescriptionMixin, HasScopeTrackMixin, TaggableMixin } from "./mixins/props";
6+
import { HasScopeTrackMixin } from "./mixins/props";
77
import { RuntimeItemsMixin } from "./mixins/runtime_items";
88
import {
99
DefaultableInMemoryEntity,
@@ -35,8 +35,6 @@ export {
3535
NamedDefaultableRepetitionImportantSettingsInMemoryEntity,
3636
NamedDefaultableRepetitionRuntimeItemsImportantSettingsContextAndRenderHashedInMemoryEntity,
3737
HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity,
38-
HasDescriptionMixin,
39-
TaggableMixin,
4038
HasScopeTrackMixin,
4139
RuntimeItemsMixin,
4240
RuntimeContextFieldMixin,
Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,33 @@
11
import type { DescriptionSchema } from "@mat3ra/esse/dist/js/types";
22

33
import type { Constructor } from "../../utils/types";
4-
import { InMemoryEntity, InMemoryEntityConstructor } from "../in_memory";
4+
import { InMemoryEntity } from "../in_memory";
55

6-
function schemaMixin(item: InMemoryEntity) {
7-
const schema = {
6+
export function hasDescriptionMixin<T extends InMemoryEntity>(item: T) {
7+
// @ts-expect-error
8+
const properties: InMemoryEntity & HasDescriptionInMemoryEntity = {
89
get description(): string {
9-
return item.prop("description", "");
10+
return this.prop("description", "");
1011
},
1112
set description(string: string) {
12-
item.setProp("description", string);
13+
this.setProp("description", string);
1314
},
1415
get descriptionObject() {
15-
return item.prop<DescriptionSchema["descriptionObject"]>("descriptionObject");
16+
return this.prop<DescriptionSchema["descriptionObject"]>("descriptionObject");
1617
},
1718
set descriptionObject(obj: DescriptionSchema["descriptionObject"]) {
18-
item.setProp("descriptionObject", obj);
19+
this.setProp("descriptionObject", obj);
1920
},
20-
} satisfies DescriptionSchema;
21+
};
2122

22-
Object.defineProperties(item, Object.getOwnPropertyDescriptors(schema));
23+
Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties));
2324

24-
return schema;
25+
return properties;
2526
}
2627

27-
export function hasDescriptionMixin(item: InMemoryEntity) {
28-
return schemaMixin(item);
29-
}
28+
export type HasDescriptionInMemoryEntity = {
29+
description: string;
30+
descriptionObject: DescriptionSchema["descriptionObject"];
31+
};
3032

31-
export type HasDescriptionInMemoryEntity = ReturnType<typeof hasDescriptionMixin>;
3233
export type HasDescriptionInMemoryEntityConstructor = Constructor<HasDescriptionInMemoryEntity>;
33-
34-
export default function HasDescriptionMixin<S extends InMemoryEntityConstructor>(superclass: S) {
35-
class HasDescriptionMixin extends superclass {
36-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
37-
constructor(...args: any[]) {
38-
super(...args);
39-
hasDescriptionMixin(this);
40-
}
41-
}
42-
43-
return HasDescriptionMixin as S & HasDescriptionInMemoryEntityConstructor;
44-
}

0 commit comments

Comments
 (0)