Add example of passing settings to view plugin#45
Add example of passing settings to view plugin#45Phrynobatrachus wants to merge 2 commits intoobsidianmd:mainfrom
Conversation
|
It's not clear to me what this example demonstrates. Could you give some more context? Also, I'd prefer to avoid using snippets from other plugins, and instead create a simpler code example that demonstrates the specific use case. |
|
static fromClass<V extends PluginValue>(cls: {new (view: EditorView) → V}, spec?: PluginSpec<V>) → ViewPlugin<V> If you want to reference your main plugin's settings in a view plugin, how do you do that given the constructor signature The original PR has a couple discord links to occasions where this came up, perhaps the second link's example is a bit cleaner? https://discord.com/channels/686053708261228577/840286264964022302/1088037085086236682 export function YOURVIEWPLUGIN(settings: YOURPLUGINSETTINGS) {
const viewPlugin = ViewPlugin.fromClass(
class {
// use settings wherever needed
constructor(view: EditorView) {
// ...
}
update(update: ViewUpdate) {
// ...
}
buildDecorations(view: EditorView): DecorationSet {
// ...
}
},
{
decorations: // Decorations go here
}
);
return viewPlugin;
} |
marcusolsson/obsidian-plugin-docs#73
Duped here since the above repo is now archived. 🍻