Skip to content

Commit cf30b19

Browse files
authored
[:recycle:] changeListener moved to the constructor (#1210)
# ✍️ Description Assigning a value to an attribute violated encapsulation, which is easy to do in JS, but still. This is a cleaner API, with a private `changeListener` which is assigned when the object is built. ### 🏗️ Works with PROD4POD-1931 Still cleaning up and refactoring the importer, looking at improving coverage. Related to #1209 and #1204, but wanted it to be considered on its own. Also it's a change of API, which is better if considered on its own.
1 parent a09c526 commit cf30b19

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

feature-utils/poly-import/src/storage.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export class FeatureFileStorage {
2-
constructor(pod) {
3-
this.changeListener = () => {};
2+
constructor(pod, changeListener = () => {}) {
3+
this._changeListener = changeListener;
44
this._files = null;
55
this._pod = pod;
66
}
@@ -29,7 +29,7 @@ export class FeatureFileStorage {
2929
const { polyOut } = this._pod;
3030
await polyOut.removeArchive(file);
3131
await this.refreshFiles();
32-
this.changeListener();
32+
this._changeListener();
3333
}
3434
}
3535

feature-utils/poly-look/src/react-components/contexts/poly-import.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,13 @@ export const PolyImportProvider = ({
5353

5454
useEffect(() => {
5555
if (!pod) return;
56-
const storage = new FeatureFileStorage(pod);
57-
storage.changeListener = async () => {
56+
const storage = new FeatureFileStorage(pod, async () => {
5857
const resolvedFiles = [];
5958
for (const file of storage.files) {
6059
resolvedFiles.push(await file);
6160
}
6261
setFiles(Object.values(resolvedFiles));
63-
};
62+
});
6463
setStorage(storage);
6564
}, [pod]);
6665

0 commit comments

Comments
 (0)