Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@uppy/utils: remove EventManager circular reference #4949

Merged
merged 1 commit into from
Feb 22, 2024

Conversation

Murderlon
Copy link
Member

@Murderlon Murderlon commented Feb 22, 2024

Users may not update all their Uppy packages at once, moving the EventManager class to core ended up breaking some users. Moving the class was necessary for the TS transition, but we could live with some duplicated code until we release 4.0.0.
This PR re-introduce the EventManager.js file as it was before the TS transition, it’s only there for backward compatibility. Uppy plugins should keep referencing the one in @uppy/core.

@Murderlon Murderlon self-assigned this Feb 22, 2024
Copy link
Contributor

Diff output files
diff --git a/packages/@uppy/utils/lib/EventManager.js b/packages/@uppy/utils/lib/EventManager.js
index fd19927..05ee7f4 100644
--- a/packages/@uppy/utils/lib/EventManager.js
+++ b/packages/@uppy/utils/lib/EventManager.js
@@ -1 +1,85 @@
-export { default } from "@uppy/core/lib/EventManager.js";
+function _classPrivateFieldLooseBase(receiver, privateKey) {
+  if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
+    throw new TypeError("attempted to use private field on non-instance");
+  }
+  return receiver;
+}
+var id = 0;
+function _classPrivateFieldLooseKey(name) {
+  return "__private_" + id++ + "_" + name;
+}
+var _uppy = _classPrivateFieldLooseKey("uppy");
+var _events = _classPrivateFieldLooseKey("events");
+export default class EventManager {
+  constructor(uppy) {
+    Object.defineProperty(this, _uppy, {
+      writable: true,
+      value: void 0,
+    });
+    Object.defineProperty(this, _events, {
+      writable: true,
+      value: [],
+    });
+    _classPrivateFieldLooseBase(this, _uppy)[_uppy] = uppy;
+  }
+  on(event, fn) {
+    _classPrivateFieldLooseBase(this, _events)[_events].push([event, fn]);
+    return _classPrivateFieldLooseBase(this, _uppy)[_uppy].on(event, fn);
+  }
+  remove() {
+    for (const [event, fn] of _classPrivateFieldLooseBase(this, _events)[_events].splice(0)) {
+      _classPrivateFieldLooseBase(this, _uppy)[_uppy].off(event, fn);
+    }
+  }
+  onFilePause(fileID, cb) {
+    this.on("upload-pause", (targetFileID, isPaused) => {
+      if (fileID === targetFileID) {
+        cb(isPaused);
+      }
+    });
+  }
+  onFileRemove(fileID, cb) {
+    this.on("file-removed", file => {
+      if (fileID === file.id) cb(file.id);
+    });
+  }
+  onPause(fileID, cb) {
+    this.on("upload-pause", (targetFileID, isPaused) => {
+      if (fileID === targetFileID) {
+        cb(isPaused);
+      }
+    });
+  }
+  onRetry(fileID, cb) {
+    this.on("upload-retry", targetFileID => {
+      if (fileID === targetFileID) {
+        cb();
+      }
+    });
+  }
+  onRetryAll(fileID, cb) {
+    this.on("retry-all", () => {
+      if (!_classPrivateFieldLooseBase(this, _uppy)[_uppy].getFile(fileID)) return;
+      cb();
+    });
+  }
+  onPauseAll(fileID, cb) {
+    this.on("pause-all", () => {
+      if (!_classPrivateFieldLooseBase(this, _uppy)[_uppy].getFile(fileID)) return;
+      cb();
+    });
+  }
+  onCancelAll(fileID, eventHandler) {
+    var _this = this;
+    this.on("cancel-all", function() {
+      if (!_classPrivateFieldLooseBase(_this, _uppy)[_uppy].getFile(fileID)) return;
+      eventHandler(...arguments);
+    });
+  }
+  onResumeAll(fileID, cb) {
+    this.on("resume-all", () => {
+      if (!_classPrivateFieldLooseBase(this, _uppy)[_uppy].getFile(fileID)) return;
+      cb();
+    });
+  }
+}

@aduh95 aduh95 merged commit ae12f39 into main Feb 22, 2024
16 checks passed
@aduh95 aduh95 deleted the revert-eventmanager-utils branch February 22, 2024 10:39
@Murderlon Murderlon linked an issue Feb 22, 2024 that may be closed by this pull request
2 tasks
Murderlon added a commit that referenced this pull request Feb 22, 2024
* main:
  Introduce `ValidateableFile` & move `MinimalRequiredUppyFile` into utils (#4944)
  uppy: fix bundle builder (#4950)
  @uppy/core: improve `UIPluginOptions` types (#4946)
  @uppy/companion-client: fix body/url on upload-success (#4922)
  @uppy/utils: remove EventManager circular reference (#4949)
@github-actions github-actions bot mentioned this pull request Feb 22, 2024
github-actions bot added a commit that referenced this pull request Feb 22, 2024
| Package                | Version | Package                | Version |
| ---------------------- | ------- | ---------------------- | ------- |
| @uppy/audio            |   1.1.7 | @uppy/react            |   3.2.2 |
| @uppy/companion        |  4.12.3 | @uppy/status-bar       |   3.2.8 |
| @uppy/companion-client |   3.7.3 | @uppy/tus              |   3.5.3 |
| @uppy/core             |   3.9.2 | @uppy/utils            |   5.7.3 |
| @uppy/dashboard        |   3.7.4 | @uppy/xhr-upload       |   3.6.3 |
| @uppy/image-editor     |   2.4.3 | uppy                   |  3.22.2 |

- @uppy/core: fix plugin detection (Antoine du Hamel / #4951)
- @uppy/core,@uppy/utils: Introduce `ValidateableFile` & move `MinimalRequiredUppyFile` into utils (Antoine du Hamel / #4944)
- meta: uppy: fix bundle builder (Antoine du Hamel / #4950)
- @uppy/core: improve `UIPluginOptions` types (Merlijn Vos / #4946)
- @uppy/companion-client: fix body/url on upload-success (Merlijn Vos / #4922)
- @uppy/utils: remove EventManager circular reference (Merlijn Vos / #4949)
- @uppy/dashboard: MetaEditor + ImageEditor - new state machine logic (Evgenia Karunus / #4939)
- meta: disable `@typescript-eslint/no-non-null-assertion` lint rule (Antoine du Hamel / #4945)
- @uppy/companion-client: remove unnecessary `'use strict'` directives (Antoine du Hamel / #4943)
- @uppy/companion-client: type changes for provider-views (Antoine du Hamel / #4938)
- meta: bump ip from 1.1.8 to 1.1.9 (dependabot[bot] / #4941)
- @uppy/companion-client: update types (Antoine du Hamel / #4927)
Murderlon added a commit that referenced this pull request Feb 26, 2024
* main:
  @uppy/file-input: refactor to TypeScript (#4954)
  Release: uppy@3.22.2 (#4952)
  @uppy/core: fix plugin detection (#4951)
  Introduce `ValidateableFile` & move `MinimalRequiredUppyFile` into utils (#4944)
  uppy: fix bundle builder (#4950)
  @uppy/core: improve `UIPluginOptions` types (#4946)
  @uppy/companion-client: fix body/url on upload-success (#4922)
  @uppy/utils: remove EventManager circular reference (#4949)
  MetaEditor + ImageEditor - new state machine logic (#4939)
  meta: disable `@typescript-eslint/no-non-null-assertion` lint rule (#4945)
  remove unnecessary `'use strict'` directives (#4943)
  @uppy/companion-client: type changes for provider-views (#4938)
  meta: bump ip from 1.1.8 to 1.1.9 (#4941)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

uppy/core 3.3.1 throws error after new build
2 participants