Skip to content

Commit

Permalink
fix type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-hub committed Jul 17, 2024
1 parent b612fe4 commit 0ceec87
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
23 changes: 11 additions & 12 deletions src/api/PluginAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BibleReferencePluginSettings } from '../data/constants'
import { VerseSuggesting } from '../verse/VerseSuggesting'
import { verseMatch } from '../utils/verseMatch'
import { getSuggestionsFromQuery } from '../utils/getSuggestionsFromQuery'
import { App } from 'obsidian'

/**
* A subset of the plugin's API, to be exposed globally for programmatic use
Expand All @@ -11,19 +12,11 @@ import { getSuggestionsFromQuery } from '../utils/getSuggestionsFromQuery'
* Many thanks to `obsidian-dataview` for the implementation reference
*/
export class BibleReferenceAPI {
settings: BibleReferencePluginSettings

public constructor(
public app: App,
public settings: BibleReferencePluginSettings
public settings: BibleReferencePluginSettings,
) {
this.settings = settings;
}

private mergeSettings(opts?: BibleReferencePluginSettings): BibleReferencePluginSettings {
return opts
? Object.assign(Object.assign({}, this.settings), opts)
: Object.assign({}, this.settings);
this.settings = settings
}

/**
Expand All @@ -35,7 +28,13 @@ export class BibleReferenceAPI {
* @param {BibleReferencePluginSettings?} [opts=undefined] - optional overrides for any settings
*/
async queryVerses(query: string, opts?: BibleReferencePluginSettings): Promise<VerseSuggesting | null> {
if ( !verseMatch(query) ) return null;
return getSuggestionsFromQuery(`${query}`, this.mergeSettings(opts)).then(verseArray => verseArray[0] || null);
if (!verseMatch(query)) return null
return getSuggestionsFromQuery(`${query}`, this.mergeSettings(opts)).then(verseArray => verseArray[0] || null)
}

private mergeSettings(opts?: BibleReferencePluginSettings): BibleReferencePluginSettings {
return opts
? Object.assign(Object.assign({}, this.settings), opts)
: Object.assign({}, this.settings)
}
}
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ export default class BibleReferencePlugin extends Plugin {
this.addVerseLookupCommand()
this.addRibbonButton()

this.api = new BibleReferenceAPI(this, this.settings);
this.api = new BibleReferenceAPI(this.app, this.settings);
// Register the api globally
// @ts-ignore
(window['BibleReferenceAPI'] = this.api) && this.register(() => { delete window['BibleReferenceAPI'] });

const flagService = FlagService.getInstace()
Expand Down

0 comments on commit 0ceec87

Please sign in to comment.