Skip to content

Commit 7ff392e

Browse files
committed
fix: prettier reformat
1 parent a3510f9 commit 7ff392e

File tree

11 files changed

+219
-207
lines changed

11 files changed

+219
-207
lines changed

src/context/mixins.js

+152-143
Original file line numberDiff line numberDiff line change
@@ -3,148 +3,157 @@ import CryptoJS from "crypto-js";
33

44
import { compareEntitiesInOrderedSetForSorting } from "../entity/set/ordered/utils";
55

6-
export const ApplicationContextMixin = (superclass) => class extends superclass {
7-
constructor(config) {
8-
super(config);
9-
if (!this.constructor.Application) {
10-
throw Error("ApplicationContextMixin: Application is undefined");
11-
}
12-
this._application = (config.context && config.context.application)
13-
|| this.constructor.Application.createDefault();
14-
}
15-
16-
get application() {
17-
return this._application;
18-
}
19-
};
20-
21-
export const MaterialContextMixin = (superclass) => class extends superclass {
22-
constructor(config) {
23-
super(config);
24-
if (!this.constructor.Material) {
25-
throw Error("MaterialContextMixin: Material is undefined");
26-
}
27-
this._material = config.context && config.context.material;
28-
if (!this._material) this._material = this.constructor.Material.createDefault();
29-
this.updateMaterialHash();
30-
}
31-
32-
// eslint-disable-next-line class-methods-use-this
33-
get isEditedIsSetToFalseOnMaterialUpdate() {
34-
return false;
35-
}
36-
37-
updateMaterialHash() {
38-
if (this.isEditedIsSetToFalseOnMaterialUpdate) this.isEdited = false;
39-
this.extraData = { materialHash: this.material.hash };
40-
}
41-
42-
// Workaround: Material.createDefault() used to initiate workflow reducer and hence here too
43-
// does not have an id. Here we catch when such material is used and avoid resetting isEdited
44-
get isMaterialCreatedDefault() {
45-
return !this.material.id;
46-
}
47-
48-
get isMaterialUpdated() {
49-
return Boolean(this.extraData && this.extraData.materialHash !== this.material.hash);
50-
}
51-
52-
get material() {
53-
return this._material;
54-
}
55-
};
56-
57-
export const MaterialsSetContextMixin = (superclass) => class extends superclass {
58-
constructor(config) {
59-
super(config);
60-
this._materialsSet = this.config.context && this.config.context.materialsSet;
61-
}
62-
63-
get materialsSet() {
64-
return this._materialsSet;
65-
}
66-
67-
sortMaterialsByIndexInSet(materials = []) {
68-
// DO NOT SORT IN PLACE AS IT CHANGES THE ORDER IN `this.materials` AND HAS SIDE EFFECTS (MaterialViewer).
69-
return materials.concat().sort((a, b) => {
70-
return compareEntitiesInOrderedSetForSorting(a, b, this.materialsSet._id, false);
71-
});
72-
}
73-
};
74-
75-
export const MaterialsContextMixin = (superclass) => class extends superclass {
76-
constructor(config) {
77-
super(config);
78-
const materials = this.config.context && this.config.context.materials;
79-
if (!this.constructor.Material) {
80-
throw Error("MaterialsContextMixin: Material is undefined");
81-
}
82-
this._materials = materials && materials.length
83-
? materials
84-
: [this.constructor.Material.createDefault()];
85-
}
86-
87-
get materials() {
88-
return this._materials;
89-
}
90-
};
91-
92-
export const MethodDataContextMixin = (superclass) => class extends superclass {
93-
constructor(config) {
94-
super(config);
95-
this._methodData = (config.context && config.context.methodData) || {};
96-
this.isEdited = false; // we always get the `defaultData` (recalculated from scratch, not persistent)
97-
}
98-
99-
/* @summary Replace the logic in constructor with this in order to enable passing `methodDataHash` between
6+
export const ApplicationContextMixin = (superclass) =>
7+
class extends superclass {
8+
constructor(config) {
9+
super(config);
10+
if (!this.constructor.Application) {
11+
throw Error("ApplicationContextMixin: Application is undefined");
12+
}
13+
this._application =
14+
(config.context && config.context.application) ||
15+
this.constructor.Application.createDefault();
16+
}
17+
18+
get application() {
19+
return this._application;
20+
}
21+
};
22+
23+
export const MaterialContextMixin = (superclass) =>
24+
class extends superclass {
25+
constructor(config) {
26+
super(config);
27+
if (!this.constructor.Material) {
28+
throw Error("MaterialContextMixin: Material is undefined");
29+
}
30+
this._material = config.context && config.context.material;
31+
if (!this._material) this._material = this.constructor.Material.createDefault();
32+
this.updateMaterialHash();
33+
}
34+
35+
// eslint-disable-next-line class-methods-use-this
36+
get isEditedIsSetToFalseOnMaterialUpdate() {
37+
return false;
38+
}
39+
40+
updateMaterialHash() {
41+
if (this.isEditedIsSetToFalseOnMaterialUpdate) this.isEdited = false;
42+
this.extraData = { materialHash: this.material.hash };
43+
}
44+
45+
// Workaround: Material.createDefault() used to initiate workflow reducer and hence here too
46+
// does not have an id. Here we catch when such material is used and avoid resetting isEdited
47+
get isMaterialCreatedDefault() {
48+
return !this.material.id;
49+
}
50+
51+
get isMaterialUpdated() {
52+
return Boolean(this.extraData && this.extraData.materialHash !== this.material.hash);
53+
}
54+
55+
get material() {
56+
return this._material;
57+
}
58+
};
59+
60+
export const MaterialsSetContextMixin = (superclass) =>
61+
class extends superclass {
62+
constructor(config) {
63+
super(config);
64+
this._materialsSet = this.config.context && this.config.context.materialsSet;
65+
}
66+
67+
get materialsSet() {
68+
return this._materialsSet;
69+
}
70+
71+
sortMaterialsByIndexInSet(materials = []) {
72+
// DO NOT SORT IN PLACE AS IT CHANGES THE ORDER IN `this.materials` AND HAS SIDE EFFECTS (MaterialViewer).
73+
return materials.concat().sort((a, b) => {
74+
return compareEntitiesInOrderedSetForSorting(a, b, this.materialsSet._id, false);
75+
});
76+
}
77+
};
78+
79+
export const MaterialsContextMixin = (superclass) =>
80+
class extends superclass {
81+
constructor(config) {
82+
super(config);
83+
const materials = this.config.context && this.config.context.materials;
84+
if (!this.constructor.Material) {
85+
throw Error("MaterialsContextMixin: Material is undefined");
86+
}
87+
this._materials =
88+
materials && materials.length
89+
? materials
90+
: [this.constructor.Material.createDefault()];
91+
}
92+
93+
get materials() {
94+
return this._materials;
95+
}
96+
};
97+
98+
export const MethodDataContextMixin = (superclass) =>
99+
class extends superclass {
100+
constructor(config) {
101+
super(config);
102+
this._methodData = (config.context && config.context.methodData) || {};
103+
this.isEdited = false; // we always get the `defaultData` (recalculated from scratch, not persistent)
104+
}
105+
106+
/* @summary Replace the logic in constructor with this in order to enable passing `methodDataHash` between
100107
* subsequent initializations of the derived class. Not used at present and kept for the record.
101108
*/
102-
_initMethodDataHash() {
103-
this.methodDataHash = CryptoJS.MD5(JSON.stringify(this.methodData)).toString();
104-
this.extraData = { methodDataHash: this.methodDataHash };
105-
if (!this._methodData) {
106-
this._methodData = {};
107-
this.isEdited = false;
108-
// Commented out to reduce effect on performance. Uncomment for debugging purposes.
109-
// TODO: remove on next refactoring or convert to log
110-
// console.warn("MethodDataContextMixin: methodData is undefined or null");
111-
} else if (this.isMethodDataUpdated) {
112-
this.isEdited = false;
113-
} else {
114-
// eslint-disable-next-line no-undef
115-
this.isEdited = config.isEdited;
116-
}
117-
}
118-
119-
get methodData() {
120-
return this._methodData;
121-
}
122-
123-
get isMethodDataUpdated() {
124-
return Boolean(this.extraData && this.extraData.methodDataHash !== this.methodDataHash);
125-
}
126-
};
127-
128-
export const WorkflowContextMixin = (superclass) => class extends superclass {
129-
constructor(config) {
130-
super(config);
131-
this._workflow = (config.context && config.context.workflow) || {};
132-
this.isEdited = false; // we always get the `defaultData` (recalculated from scratch, not persistent)
133-
}
134-
135-
get workflow() {
136-
return this._workflow;
137-
}
138-
};
139-
140-
export const JobContextMixin = (superclass) => class extends superclass {
141-
constructor(config) {
142-
super(config);
143-
this._job = (config.context && config.context.job) || {};
144-
this.isEdited = false; // we always get the `defaultData` (recalculated from scratch, not persistent)
145-
}
146-
147-
get job() {
148-
return this._job;
149-
}
150-
};
109+
_initMethodDataHash() {
110+
this.methodDataHash = CryptoJS.MD5(JSON.stringify(this.methodData)).toString();
111+
this.extraData = { methodDataHash: this.methodDataHash };
112+
if (!this._methodData) {
113+
this._methodData = {};
114+
this.isEdited = false;
115+
// Commented out to reduce effect on performance. Uncomment for debugging purposes.
116+
// TODO: remove on next refactoring or convert to log
117+
// console.warn("MethodDataContextMixin: methodData is undefined or null");
118+
} else if (this.isMethodDataUpdated) {
119+
this.isEdited = false;
120+
} else {
121+
// eslint-disable-next-line no-undef
122+
this.isEdited = config.isEdited;
123+
}
124+
}
125+
126+
get methodData() {
127+
return this._methodData;
128+
}
129+
130+
get isMethodDataUpdated() {
131+
return Boolean(this.extraData && this.extraData.methodDataHash !== this.methodDataHash);
132+
}
133+
};
134+
135+
export const WorkflowContextMixin = (superclass) =>
136+
class extends superclass {
137+
constructor(config) {
138+
super(config);
139+
this._workflow = (config.context && config.context.workflow) || {};
140+
this.isEdited = false; // we always get the `defaultData` (recalculated from scratch, not persistent)
141+
}
142+
143+
get workflow() {
144+
return this._workflow;
145+
}
146+
};
147+
148+
export const JobContextMixin = (superclass) =>
149+
class extends superclass {
150+
constructor(config) {
151+
super(config);
152+
this._job = (config.context && config.context.job) || {};
153+
this.isEdited = false; // we always get the `defaultData` (recalculated from scratch, not persistent)
154+
}
155+
156+
get job() {
157+
return this._job;
158+
}
159+
};

src/context/provider.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ export class ContextProvider {
5050
config,
5151
data
5252
? {
53-
data,
54-
extraData,
55-
isEdited,
56-
}
53+
data,
54+
extraData,
55+
isEdited,
56+
}
5757
: {},
5858
);
5959
}

src/entity/mixins/runtime_items.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ export const RuntimeItemsUILogicMixin = (superclass) => {
6363
}
6464

6565
setRuntimeItemsToDefaultValues() {
66-
["results", "monitors", "preProcessors", "postProcessors"].map((name) => this.setProp(name, this[`default${s.capitalize(name)}`]));
66+
["results", "monitors", "preProcessors", "postProcessors"].map((name) =>
67+
this.setProp(name, this[`default${s.capitalize(name)}`]),
68+
);
6769
}
6870

6971
/**

src/entity/set/factory.js

+10-12
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ import { InMemoryEntitySet } from "../set";
22
import { ENTITY_SET_TYPES } from "./enums";
33
import { OrderedInMemoryEntitySet } from "./ordered";
44

5-
export const constructEntitySetFactoryByConfig = ({
6-
entitySetCls = InMemoryEntitySet,
7-
orderedEntitySetCls = OrderedInMemoryEntitySet,
8-
}) => (config, entityCls) => {
9-
const Cls = config.entitySetType === ENTITY_SET_TYPES.ordered
10-
? orderedEntitySetCls
11-
: entitySetCls;
12-
return new Cls({
13-
...config,
14-
entityCls,
15-
});
16-
};
5+
export const constructEntitySetFactoryByConfig =
6+
({ entitySetCls = InMemoryEntitySet, orderedEntitySetCls = OrderedInMemoryEntitySet }) =>
7+
(config, entityCls) => {
8+
const Cls =
9+
config.entitySetType === ENTITY_SET_TYPES.ordered ? orderedEntitySetCls : entitySetCls;
10+
return new Cls({
11+
...config,
12+
entityCls,
13+
});
14+
};

0 commit comments

Comments
 (0)