Skip to content

Conversation

Leilei332
Copy link
Contributor

Deprecate & simplify some utility functions that are supported in ES2017.

Copy link

netlify bot commented Aug 15, 2025

Deploy Preview for tiddlywiki-previews ready!

Name Link
🔨 Latest commit 317d720
🔍 Latest deploy log https://app.netlify.com/projects/tiddlywiki-previews/deploys/68de0b09e9de9a0008617b72
😎 Deploy Preview https://deploy-preview-9251--tiddlywiki-previews.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

Confirmed: Leilei332 has already signed the Contributor License Agreement (see contributing.md)

Copy link

github-actions bot commented Aug 15, 2025

📊 Build Size Comparison: empty.html

Branch Size
Base (master) 2418.3 KB
PR 2415.3 KB

Diff: ⬇️ Decrease: 3.0 KB

@Jermolene
Copy link
Member

Thanks @Leilei332 this is very encouraging, a decent size reduction and much better readability. Do you plan to refactor away the usages of these deprecated methods in this PR?

@Leilei332
Copy link
Contributor Author

Leilei332 commented Aug 24, 2025

Thanks @Leilei332 this is very encouraging, a decent size reduction and much better readability. Do you plan to refactor away the usages of these deprecated methods in this PR?

I'd love to, but I'm afraid that I will become busy in September. Besides:

  1. Refactoring may cause conflict with the existing PRs.
  2. Some tw utility functions don't have the same behavior as standard ones (like pad, trim).

Considering these risks, I agree with what Mario said in #7353. IMO the best solution is to rewrite deprecated utility functions to use standard methods, and let developers know they are deprecated and not use them (I think an advantage of #8533 is that it allows a popup to be displayed to show the function is deprecated when a developer is using a deprecated api by using @deprecated).

@saqimtiaz
Copy link
Member

@Leilei332 if you have the opportunity, perhaps have a look at

exports.convertEventName = function(eventName) {
if(eventNameCache[eventName]) {
return eventNameCache[eventName];
}
var newEventName = eventName,
mappings = eventNameMappings[eventName];
if(mappings) {
var convertedProperty = $tw.utils.convertStyleNameToPropertyName(mappings.correspondingCssProperty);
if(mappings.mappings[convertedProperty]) {
newEventName = mappings.mappings[convertedProperty];
}
}
// Put it in the cache too
eventNameCache[eventName] = newEventName;
return newEventName;
};
/*
Return the names of the fullscreen APIs
*/
exports.getFullScreenApis = function() {
var d = document,
db = d.body,
result = {
"_requestFullscreen": db.webkitRequestFullscreen !== undefined ? "webkitRequestFullscreen" :
db.mozRequestFullScreen !== undefined ? "mozRequestFullScreen" :
db.msRequestFullscreen !== undefined ? "msRequestFullscreen" :
db.requestFullscreen !== undefined ? "requestFullscreen" : "",
"_exitFullscreen": d.webkitExitFullscreen !== undefined ? "webkitExitFullscreen" :
d.mozCancelFullScreen !== undefined ? "mozCancelFullScreen" :
d.msExitFullscreen !== undefined ? "msExitFullscreen" :
d.exitFullscreen !== undefined ? "exitFullscreen" : "",
"_fullscreenElement": d.webkitFullscreenElement !== undefined ? "webkitFullscreenElement" :
d.mozFullScreenElement !== undefined ? "mozFullScreenElement" :
d.msFullscreenElement !== undefined ? "msFullscreenElement" :
d.fullscreenElement !== undefined ? "fullscreenElement" : "",
"_fullscreenChange": d.webkitFullscreenElement !== undefined ? "webkitfullscreenchange" :
d.mozFullScreenElement !== undefined ? "mozfullscreenchange" :
d.msFullscreenElement !== undefined ? "MSFullscreenChange" :
d.fullscreenElement !== undefined ? "fullscreenchange" : ""
};
if(!result._requestFullscreen || !result._exitFullscreen || !result._fullscreenElement || !result._fullscreenChange) {
return null;
} else {
return result;
}
};
for some more utility methods that can be deprecated.

@Leilei332
Copy link
Contributor Author

getFullscreenApis can be simplified, but can't be deprecated. Standard fullscreen api is 2023 baseline. We can simplify this function to use only webkit vendor prefix.

@Leilei332 Leilei332 changed the title Deprecate some utility functions Deprecate and simplify some utility functions Sep 13, 2025
@Jermolene
Copy link
Member

Hi @Leilei332 this is looking great, thank you.

One small thing is that I think it would be helpful to adopt a more distinctive, searchable marker for deprecation comments. Something like:

//:Deprecated: Something something something

And then we could introduce further structured comments that use the same prefix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready

Development

Successfully merging this pull request may close these issues.

5 participants