-
Notifications
You must be signed in to change notification settings - Fork 214
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
Deprecate IDisposable and related utilities #7309
base: master
Are you sure you want to change the base?
Conversation
I want to see what output the linter produces. You've presumably introduced a ton of deprecation warnings. I'd remove all the |
This is actually passing lint without any errors in its current state - looks like the |
I'd remove |
Over the last few weeks I have been running into issues in my deployed app where it complains about "Uncaught SyntaxError: Missing initializer in using declaration". I'm not necessarily sure if this is browser specific or not, I know others are not able to repro with the same version of chrome(Version 131.0.6778.109 (Official Build) (arm64)), and if I switch browsers it works fine. I havent investigated too much, but I think the changes in this PR would help solve it. Not sure why when I build my app, depending on the browser it decides to use the global |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
core-geometry change is good.
docs/changehistory/NextVersion.md
Outdated
} | ||
``` | ||
|
||
> Note that while public types with deterministic cleanup logic in iTwin.js will continue to implement _both_ `IDisposable` and `Disposable` until the former is fully removed in iTwin.js 7.0 (in accordance with our [API support policy](../learning/api-support-policies)), disposable objects should still only be disposed once - _either_ with [IDisposable.dispose]($core-bentley) _or_ `Symbol.dispose()` but not both! Where possible, prefer `using` declarations or the [dispose]($core-bentley) helper function over directly calling either method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: idk if you should explicitly mention a future version, and i dont think you need to call out the support policy
@@ -20,6 +20,29 @@ Table of contents: | |||
|
|||
## API deprecations | |||
|
|||
### @itwin/core-bentley |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: missing in the ToC above
only update this if you are reacting to the other comment on this file. this will get fixed automatically by the next time someone edits this file and has markdownlint/formatters enabled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mobile changes look fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presentation: did some cleanup, fixed coverage not being 100%. Thanks for taking this up!
This pull request is now in conflicts. Could you fix it @wgoehrig? 🙏 |
I've been making similar changes in Here's a hypothetical situation before the changes: class Ours {
public dispose() {
// do our dispose
}
}
class Theirs extends Ours {
public override dispose() {
super.dispose();
// do their dispose
}
}
function useAndDispose(factory: () => Ours) {
const instance = factory();
// ... do something with instance
// the below call does theirs as well as ours dispose:
instance.dispose();
} There could be problems with class Ours {
public [Symbol.dispose]() {
// do our dispose
}
/** @deprecated */
public dispose() {
this[Symbol.dispose]();
}
}
// this class has not been updated to use the new disposal method:
class Theirs extends Ours {
public override dispose() {
super.dispose();
// do their dispose
}
}
function useAndDispose(factory: () => Ours) {
// this won't do "theirs dispose"!
using instance = factory();
// this wouldn't either:
const instance = factory();
instance[Symbol.dispose]();
// and even this wouldn't:
const instance = factory();
if (isDisposable(instance)) {
instance[Symbol.dispose]();
} else if (isIDisposable(instance)) {
instance.dispose();
}
// only this would:
const instance = factory();
if (isIDisposable(instance)) {
instance.dispose();
} else if (isDisposable(instance)) {
instance[Symbol.dispose]();
}
} It seems we should be very careful about only calling |
I agree this is an important consideration - I checked earlier with @pmconne and he seemed confident that we don't have any patterns in at least the render system where ownership is "transferred" in this way (i.e., where we're responsible for the disposal of something passed in). @grigasp are you aware of anywhere that's happening in presentation? |
There is one place... In the |
So I have unknowingly fixed this in my app. Changed sourcemap config option in vite from Either way, I think this PR is still in our best interest to complete. |
This pull request is now in conflicts. Could you fix it @wgoehrig? 🙏 |
Since TypeScript 5.2 added support for the explicit resource management feature in ECMAScript, let's deprecate IDisposable and use the new built-in Disposable instead.