andrewbrereton / obsidian-to-ical-plugin

This is a plugin for Obsidian that searches your vault for tasks that contain dates, and generates a calendar in iCal format that can be imported into your preferred calendar application.
MIT License
56 stars 10 forks source link

(Architecure) Parameters as singleton #49

Closed Blondwolf closed 7 months ago

Blondwolf commented 7 months ago

This ticket is to discuss about wether or not it would be a good idea to create a singleton to store global settings as mentioned here

Blondwolf commented 7 months ago

Not sure about this personally. I dont find much documentation about Obsidian plugins dev.

It feels like this.settings.isDebug for example can be accessible directly from the Plugin class. So the Plugin already has this settings. You could just send those setting in a class which is already created src/Model/Settings.js.

If you want to simplify the parameters, you can just pass this.settings from the main to other classes you need for treatment.

Then instead of

this.taskFinder = new TaskFinder(this.app.vault, this.settings.howToParseInternalLinks, this.settings.ignoreCompletedTasks, this.settings.ignoreOldTasks, this.settings.oldTaskInDays, this.settings.isIncludeTodos);

You can do

this.taskFinder = new TaskFinder(this.app.vault, this.settings);

And then process to get them back in the class the same way you would do with a singleton

this.howToParseInternalLinks = settings.howToParseInternalLinks;
this.ignoreCompletedTasks = settings.ignoreCompletedTasks;
andrewbrereton commented 7 months ago

Resolved in https://github.com/andrewbrereton/obsidian-to-ical-plugin/pull/51 and released in 1.15.0.