-
-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add mathjs
singleton and expose it via API
#481
base: master
Are you sure you want to change the base?
Conversation
This allows for modification of `mathjs` by the user, mostly to allow for the use of `math.import` to define custom functions
> [!Note] | ||
> Please note the second parameter for `math.import`. | ||
> Passing `silent:true` leads to the function <u>not</u> beeing updated on edit! (only on reload of meta-bind) | ||
> Pass `override:true` to override the function everytime you switch between edit and viewing mode. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sentence is probably incorrect. You override the function every time the code block reruns, which is not necessarily when switching editor modes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point.
I also though about if the example should be in a more "playing around" friendly way. So just having it as override:true
might be better and saves the troubles of having to add the note
@@ -13,12 +13,15 @@ export class MathVF extends AbstractViewField<unknown> { | |||
expression?: EvalFunction; | |||
expressionStr?: string; | |||
hasError: boolean; | |||
math: MathJsInstance; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you add this math
member variable couldn't you get the singleton directly on line 54?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about this and started this way because I expected to need multiple accesses, but than ended up not.
I was also unsure how this might change depending on the liftime of the singleton / multiple instances, so I left it being initialized by the constructor.
But fine to change if the singleton-pattern is staying
This brings up an important point. The additions to mathjs only work once the code adding them has run. Code block execution order in a file is usually top to bottom, but that is not guaranteed. They can theoretically run in any order, so math view fields could run before the js-engine code block adding the needed mathjs extensions. One approach could be to enable users to somehow register global mathjs extensions on plugin load. |
that would be super annoying if it happens randomly sometimes.
I also thought about adding a config option where the user could input a object to initialize the context with. This was just the quickest way to get a working version to test if it works at all. |
yeah, maybe a path to a JS file that get's run via js-engine at statup |
I like the Idea, maybe identically to how Base Obsidian handles css snippets, just as JS snippets. But it starts to feel more like it should be a Feature of JS-engine now? |
Yeah. Maybe it's better to just add a simple API to MB and the startup script thing to js-engine |
After a few days of thought, I want to go with a simple API on the MB side and adding startup scripts to js-engine. |
I just released statup scripts in js-engine |
This allows for modification of
mathjs
by the user, mostly to allow for the use ofmath.import
to define custom functions.See the new
Advanced Examples/Customising mathjs
for details.closes #480
This is a first implementation, it works but I am sure there are better ways to implement the singleton.
Finding the right place in the lifecycle of the app just went over my head
I am also unsure if the
MathjsInstance
should be per-app or per file?