Skip to content

feat: Add obisidian API's free functions to API#86

Closed
dljsjr wants to merge 4 commits intoblacksmithgu:masterfrom
dljsjr:pr/feat/obsidian-free-functions
Closed

feat: Add obisidian API's free functions to API#86
dljsjr wants to merge 4 commits intoblacksmithgu:masterfrom
dljsjr:pr/feat/obsidian-free-functions

Conversation

@dljsjr
Copy link
Contributor

@dljsjr dljsjr commented Feb 20, 2025

Adds the Obsidian free functions to the app object under the functions object.

This provides access to a bunch of useful built-in Obsidian utilities via the local API.

Adds the obsidian free functions to the `app` object under the
`functions` object.
@blacksmithgu
Copy link
Owner

Aren't these already available as app.<function>? I thought the Obsidian app object was already in the global context.

@FeralFlora
Copy link

Aren't these already available as app.<function>? I thought the Obsidian app object was already in the global context.

Usage of global app is discouraged, see:
https://docs.obsidian.md/Plugins/Releasing/Plugin+guidelines#Avoid+using+global+app+instance

and:
https://github.com/Fevol/obsidian-typings/blob/main/CHANGELOG.md#114

NOTE: the global app variable has been removed from the official Obsidian API as of 1.6.0, it will not be re-added by obsidian-typings

@dljsjr
Copy link
Contributor Author

dljsjr commented Mar 5, 2025

Aren't these already available as app.<function>? I thought the Obsidian app object was already in the global context.

No, the free functions like normalizePath aren't attached to the app object. They're exported as part of the obsidian namespace, meaning they aren't available to code blocks since you can't import "obsidian"

@RyotaUshio
Copy link
Contributor

RyotaUshio commented Mar 18, 2025

I'm afraid I don't think it's a great idea to modify the app object itself. Also, exposing the obsidian module to the global context can be helpful but is it really inside Datacore's scope?
It might make sense if it is added to the local scope where we write queries.

Copy link
Collaborator

@GamerGirlandCo GamerGirlandCo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good work. keep in mind that monkey patching app is advised against, because it's not a matter of "if" but "when" an update to obsidian itself will break everything.

@GamerGirlandCo
Copy link
Collaborator

closing - superseded by #160

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.

5 participants