Skip to content

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

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

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

Conversation

@dljsjr

@dljsjr dljsjr commented Feb 20, 2025

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Owner

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

@FeralFlora

Copy link
Copy Markdown

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

dljsjr commented Mar 5, 2025

Copy link
Copy Markdown
Contributor Author

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

RyotaUshio commented Mar 18, 2025

Copy link
Copy Markdown
Contributor

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.

@GamerGirlandCo GamerGirlandCo left a comment

Copy link
Copy Markdown
Collaborator

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.

Comment thread src/typings/obsidian-ex.d.ts Outdated
Comment thread src/main.ts Outdated
@GamerGirlandCo

Copy link
Copy Markdown
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