You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The output shows that the custom relation functions do not seem to be used. (E.g. when I put a debugger into them).
Oddly enough this seems to be related somehow to how the browser bundler is working, because the same code is working for me when using Vite to bundle it from node_modules.
Been trying to figure out what's going on for a couple of hours now, and frankly hitting a wall 😟.
The text was updated successfully, but these errors were encountered:
(Btw, just a workaround in case someone does encounter this, you can directly call the factory metohd with an empty context to overwrite the functions on the instance, but I am not sure what side effects that might have.)
Hm yeah that is confusing, sorry. Let me try to explain what's going on.
The npm library contains a static function create(factories, config), and a collection of factory functions all and individual factories. When you create a mathjs instance like math = create(factories, config), it will contain a function math.create(config) which is bound to the factories of the original instance. So, it is not the same as the static version and can only create a new instance with the same factories and a changed configuration. Probably a better name for this function would be math.cloneInstance(config) or something like that.
Now, the browser bundle is not the same as the npm library: it exports a mathjs instance. So, the not the static function create(factories, config) and factory functions all, but the bound function math.create(config). The browser bundle doesn't have the collection all like the npm import does (if you print all in your jsfiddle, you will see it is undefined).
So in short: it's not possible to do with the browser bundle right now. It would be good to think through if we can address this issue.
I did a quick test: if we change the contents of defaultInstance.js to the following:
import*asmathfrom'./index.js'exportdefaultmath
And then create the browser bundle, your jsfiddle example works as expected. The browser bundle grows from 183 KB to 202 KB when zipped: it is larger because it now exports all named factories.
Here is a JSFiddle with MathJS 14 using a direct copy of the custom_relation_functions code:
https://jsfiddle.net/uonxj72q/
The output shows that the custom relation functions do not seem to be used. (E.g. when I put a debugger into them).
Oddly enough this seems to be related somehow to how the browser bundler is working, because the same code is working for me when using Vite to bundle it from node_modules.
Been trying to figure out what's going on for a couple of hours now, and frankly hitting a wall 😟.
The text was updated successfully, but these errors were encountered: