Skip to content

Commit 55dea8d

Browse files
authored
Merge pull request #123 from Exabyte-io/chore/SOF-7640
SOF-7640: small mixins cleanups
2 parents 4066190 + 72a4dd0 commit 55dea8d

31 files changed

+271
-592
lines changed

dist/js/entity/index.d.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { InMemoryEntity } from "./in_memory";
22
import { ContextAndRenderFieldsMixin } from "./mixins/context";
33
import { RuntimeContextFieldMixin } from "./mixins/context_runtime";
44
import { FlowchartEntityMixin, FlowchartItemMixin } from "./mixins/flowchart";
5-
import { HashedInputArrayMixin } from "./mixins/hash";
6-
import { DefaultableMixin, HasConsistencyChecksMixin, HasDescriptionMixin, HasMetadataMixin, HasScopeTrackMixin, NamedEntityMixin, TaggableMixin } from "./mixins/props";
5+
import { HasScopeTrackMixin } from "./mixins/props";
76
import { RuntimeItemsMixin } from "./mixins/runtime_items";
87
import { DefaultableInMemoryEntity, HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity, HasMetadataNamedDefaultableInMemoryEntity, NamedDefaultableInMemoryEntity, NamedDefaultableRepetitionContextAndRenderInMemoryEntity, NamedDefaultableRepetitionImportantSettingsInMemoryEntity, NamedDefaultableRepetitionRuntimeItemsImportantSettingsContextAndRenderHashedInMemoryEntity, NamedInMemoryEntity } from "./other";
98
import { InMemoryEntitySet } from "./set";
@@ -12,4 +11,4 @@ import { constructEntitySetFactoryByConfig } from "./set/factory";
1211
import { InMemoryEntityInSetMixin, InMemoryEntitySetMixin } from "./set/mixins";
1312
import { OrderedInMemoryEntityInSetMixin, OrderedInMemoryEntitySetMixin } from "./set/ordered/mixins";
1413
import * as selectorsForEntitySet from "./set/selectors";
15-
export { InMemoryEntity, NamedInMemoryEntity, DefaultableInMemoryEntity, NamedDefaultableInMemoryEntity, HasMetadataNamedDefaultableInMemoryEntity, NamedDefaultableRepetitionContextAndRenderInMemoryEntity, NamedDefaultableRepetitionImportantSettingsInMemoryEntity, NamedDefaultableRepetitionRuntimeItemsImportantSettingsContextAndRenderHashedInMemoryEntity, HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity, HasConsistencyChecksMixin, DefaultableMixin, HasDescriptionMixin, HasMetadataMixin, TaggableMixin, HasScopeTrackMixin, NamedEntityMixin, RuntimeItemsMixin, RuntimeContextFieldMixin, HashedInputArrayMixin, InMemoryEntitySet, ENTITY_SET_TYPES, constructEntitySetFactoryByConfig, selectorsForEntitySet, InMemoryEntitySetMixin, InMemoryEntityInSetMixin, OrderedInMemoryEntitySetMixin, OrderedInMemoryEntityInSetMixin, ContextAndRenderFieldsMixin, FlowchartEntityMixin, FlowchartItemMixin, };
14+
export { InMemoryEntity, NamedInMemoryEntity, DefaultableInMemoryEntity, NamedDefaultableInMemoryEntity, HasMetadataNamedDefaultableInMemoryEntity, NamedDefaultableRepetitionContextAndRenderInMemoryEntity, NamedDefaultableRepetitionImportantSettingsInMemoryEntity, NamedDefaultableRepetitionRuntimeItemsImportantSettingsContextAndRenderHashedInMemoryEntity, HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity, HasScopeTrackMixin, RuntimeItemsMixin, RuntimeContextFieldMixin, InMemoryEntitySet, ENTITY_SET_TYPES, constructEntitySetFactoryByConfig, selectorsForEntitySet, InMemoryEntitySetMixin, InMemoryEntityInSetMixin, OrderedInMemoryEntitySetMixin, OrderedInMemoryEntityInSetMixin, ContextAndRenderFieldsMixin, FlowchartEntityMixin, FlowchartItemMixin, };

dist/js/entity/index.js

Lines changed: 1 addition & 9 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.NamedEntityMixin = exports.HasScopeTrackMixin = exports.TaggableMixin = exports.HasMetadataMixin = exports.HasDescriptionMixin = exports.DefaultableMixin = exports.HasConsistencyChecksMixin = 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.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");
@@ -43,16 +43,8 @@ Object.defineProperty(exports, "RuntimeContextFieldMixin", { enumerable: true, g
4343
const flowchart_1 = require("./mixins/flowchart");
4444
Object.defineProperty(exports, "FlowchartEntityMixin", { enumerable: true, get: function () { return flowchart_1.FlowchartEntityMixin; } });
4545
Object.defineProperty(exports, "FlowchartItemMixin", { enumerable: true, get: function () { return flowchart_1.FlowchartItemMixin; } });
46-
const hash_1 = require("./mixins/hash");
47-
Object.defineProperty(exports, "HashedInputArrayMixin", { enumerable: true, get: function () { return hash_1.HashedInputArrayMixin; } });
4846
const props_1 = require("./mixins/props");
49-
Object.defineProperty(exports, "DefaultableMixin", { enumerable: true, get: function () { return props_1.DefaultableMixin; } });
50-
Object.defineProperty(exports, "HasConsistencyChecksMixin", { enumerable: true, get: function () { return props_1.HasConsistencyChecksMixin; } });
51-
Object.defineProperty(exports, "HasDescriptionMixin", { enumerable: true, get: function () { return props_1.HasDescriptionMixin; } });
52-
Object.defineProperty(exports, "HasMetadataMixin", { enumerable: true, get: function () { return props_1.HasMetadataMixin; } });
5347
Object.defineProperty(exports, "HasScopeTrackMixin", { enumerable: true, get: function () { return props_1.HasScopeTrackMixin; } });
54-
Object.defineProperty(exports, "NamedEntityMixin", { enumerable: true, get: function () { return props_1.NamedEntityMixin; } });
55-
Object.defineProperty(exports, "TaggableMixin", { enumerable: true, get: function () { return props_1.TaggableMixin; } });
5648
const runtime_items_1 = require("./mixins/runtime_items");
5749
Object.defineProperty(exports, "RuntimeItemsMixin", { enumerable: true, get: function () { return runtime_items_1.RuntimeItemsMixin; } });
5850
const other_1 = require("./other");
Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
import type { Constructor } from "../../utils/types";
22
import { InMemoryEntity } from "../in_memory";
3-
type ClassBase = Constructor<InMemoryEntity> & {
3+
export declare function defaultableEntityMixin<T extends InMemoryEntity>(item: T): InMemoryEntity & DefaultableInMemoryEntity;
4+
export declare function defaultableEntityStaticMixin(Item: Constructor<InMemoryEntity>): DefaultableInMemoryStaticEntity & Constructor<InMemoryEntity> & Constructor<DefaultableInMemoryEntity> & {
45
defaultConfig?: object | null;
56
};
6-
export declare function defaultableMixinProps<T extends InMemoryEntity>(item: T): {
7+
export type DefaultableInMemoryEntity = {
78
isDefault: boolean;
89
};
9-
declare const staticProperties: {
10-
createDefault<T extends ClassBase>(this: T): InstanceType<T> & DefaultableInMemoryEntity;
10+
export type DefaultableInMemoryStaticEntity = {
11+
createDefault: () => InMemoryEntity & DefaultableInMemoryEntity;
1112
};
12-
export declare function defaultableMixinStaticProps<T extends ClassBase>(Item: T): {
13-
createDefault<T_1 extends ClassBase>(this: T_1): InstanceType<T_1> & DefaultableInMemoryEntity;
14-
};
15-
export type DefaultableInMemoryEntity = ReturnType<typeof defaultableMixinProps>;
16-
export type DefaultableInMemoryEntityConstructor = Constructor<DefaultableInMemoryEntity>;
17-
export type DefaultableConstructor = DefaultableInMemoryEntityConstructor & typeof staticProperties;
18-
export default function DefaultableMixin<S extends ClassBase>(superclass: S): S & DefaultableConstructor;
19-
export {};
13+
export type DefaultableInMemoryEntityConstructor = Constructor<DefaultableInMemoryEntity> & DefaultableInMemoryStaticEntity;
Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,28 @@
11
"use strict";
2+
/* eslint-disable @typescript-eslint/no-explicit-any */
23
Object.defineProperty(exports, "__esModule", { value: true });
3-
exports.defaultableMixinProps = defaultableMixinProps;
4-
exports.defaultableMixinStaticProps = defaultableMixinStaticProps;
5-
exports.default = DefaultableMixin;
6-
function defaultableMixinProps(item) {
4+
exports.defaultableEntityMixin = defaultableEntityMixin;
5+
exports.defaultableEntityStaticMixin = defaultableEntityStaticMixin;
6+
function defaultableEntityMixin(item) {
7+
// @ts-expect-error
78
const properties = {
89
get isDefault() {
9-
return item.prop("isDefault", false);
10+
return this.prop("isDefault", false);
1011
},
1112
set isDefault(isDefault) {
12-
item.setProp("isDefault", isDefault);
13+
this.setProp("isDefault", isDefault);
1314
},
1415
};
1516
Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties));
1617
return properties;
1718
}
18-
const staticProperties = {
19-
createDefault() {
20-
return new this(this.defaultConfig);
21-
},
22-
};
23-
function defaultableMixinStaticProps(Item) {
19+
function defaultableEntityStaticMixin(Item) {
20+
// @ts-expect-error
21+
const staticProperties = {
22+
createDefault() {
23+
return new this(this.defaultConfig);
24+
},
25+
};
2426
Object.defineProperties(Item, Object.getOwnPropertyDescriptors(staticProperties));
2527
return staticProperties;
2628
}
27-
function DefaultableMixin(superclass) {
28-
class DefaultableMixin extends superclass {
29-
constructor(...args) {
30-
super(...args);
31-
defaultableMixinProps(this);
32-
}
33-
}
34-
defaultableMixinStaticProps(DefaultableMixin);
35-
return DefaultableMixin;
36-
}
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import type { ConsistencyCheck } from "@mat3ra/esse/dist/js/types";
22
import type { Constructor } from "../../utils/types";
3-
import { InMemoryEntity, InMemoryEntityConstructor } from "../in_memory";
4-
export declare function hasConsistencyChecksMixin(item: InMemoryEntity): {
5-
addConsistencyChecks(array: ConsistencyCheck[]): void;
3+
import { InMemoryEntity } from "../in_memory";
4+
export declare function hasConsistencyChecksMixin<T extends InMemoryEntity>(item: T): InMemoryEntity & HasConsistencyChecksInMemoryEntity;
5+
export type HasConsistencyChecksInMemoryEntity = {
66
consistencyChecks: ConsistencyCheck[];
7+
addConsistencyChecks: (array: ConsistencyCheck[]) => void;
78
};
8-
export type HasConsistencyChecksInMemoryEntity = ReturnType<typeof hasConsistencyChecksMixin>;
99
export type HasConsistencyChecksInMemoryEntityConstructor = Constructor<HasConsistencyChecksInMemoryEntity>;
10-
export default function HasConsistencyChecksMixin<S extends InMemoryEntityConstructor>(superclass: S): S & HasConsistencyChecksInMemoryEntityConstructor;
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.hasConsistencyChecksMixin = hasConsistencyChecksMixin;
4-
exports.default = HasConsistencyChecksMixin;
5-
function schemaMixin(item) {
6-
const schema = {
4+
function hasConsistencyChecksMixin(item) {
5+
// @ts-expect-error
6+
const properties = {
77
get consistencyChecks() {
8-
return item.prop("consistencyChecks", []);
8+
return this.prop("consistencyChecks", []);
99
},
1010
set consistencyChecks(array) {
11-
item.setProp("consistencyChecks", array);
11+
this.setProp("consistencyChecks", array);
1212
},
13-
};
14-
Object.defineProperties(item, Object.getOwnPropertyDescriptors(schema));
15-
return schema;
16-
}
17-
function propertiesMixin(item) {
18-
const properties = {
1913
addConsistencyChecks(array) {
20-
item.consistencyChecks = [...(item.consistencyChecks || []), ...array];
14+
this.consistencyChecks = [...(this.consistencyChecks || []), ...array];
2115
},
2216
};
2317
Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties));
2418
return properties;
2519
}
26-
function hasConsistencyChecksMixin(item) {
27-
return {
28-
...schemaMixin(item),
29-
...propertiesMixin(item),
30-
};
31-
}
32-
function HasConsistencyChecksMixin(superclass) {
33-
class HasConsistencyChecksMixin extends superclass {
34-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
35-
constructor(...args) {
36-
super(...args);
37-
hasConsistencyChecksMixin(this);
38-
}
39-
}
40-
return HasConsistencyChecksMixin;
41-
}
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 { InMemoryEntity, InMemoryEntityConstructor } from "../in_memory";
3-
export declare function hasMetadataMixin(item: InMemoryEntity): {
4-
updateMetadata(object: object): void;
2+
import { InMemoryEntity } from "../in_memory";
3+
export declare function hasMetadataMixin<T extends InMemoryEntity>(item: T): InMemoryEntity & HasMetadataInMemoryEntity;
4+
export type HasMetadataInMemoryEntity = {
55
metadata: object;
6+
updateMetadata: (object: object) => void;
67
};
7-
export type HasMetadataInMemoryEntity = ReturnType<typeof hasMetadataMixin>;
88
export type HasMetadataInMemoryEntityConstructor = Constructor<HasMetadataInMemoryEntity>;
9-
export default function HasMetadataMixin<S extends InMemoryEntityConstructor>(superclass: S): S & HasMetadataInMemoryEntityConstructor;
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.hasMetadataMixin = hasMetadataMixin;
4-
exports.default = HasMetadataMixin;
5-
function schemaMixin(item) {
6-
const schema = {
4+
function hasMetadataMixin(item) {
5+
// @ts-expect-error
6+
const properties = {
77
get metadata() {
8-
return item.prop("metadata", {});
8+
return this.prop("metadata", {});
99
},
1010
set metadata(object) {
11-
item.setProp("metadata", object);
11+
this.setProp("metadata", object);
1212
},
13-
};
14-
Object.defineProperties(item, Object.getOwnPropertyDescriptors(schema));
15-
return schema;
16-
}
17-
function propertiesMixin(item) {
18-
const properties = {
1913
updateMetadata(object) {
20-
item.metadata = { ...item.metadata, ...object };
14+
this.metadata = { ...this.metadata, ...object };
2115
},
2216
};
2317
Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties));
2418
return properties;
2519
}
26-
function hasMetadataMixin(item) {
27-
return {
28-
...schemaMixin(item),
29-
...propertiesMixin(item),
30-
};
31-
}
32-
function HasMetadataMixin(superclass) {
33-
class HasMetadataMixin extends superclass {
34-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
35-
constructor(...args) {
36-
super(...args);
37-
hasMetadataMixin(this);
38-
}
39-
}
40-
return HasMetadataMixin;
41-
}

0 commit comments

Comments
 (0)