Config changes in unitmath #2667
Replies: 20 comments
-
heee you have a new avatar, where did the white helmet go ;) In v6 the challenge was that I wanted to turn all functions into standalone, pure functions. This is supported now, though we still needed a way to listen for config changes in some cases, like BigNumber and Unit. I'm not fully happy with the hybrid solution solution, though at least we now have the possibility to have standalone functions. The underlying mechanism is roughly the same as in mathjs v5: You can still subscribe to listen for changes in config using the dependency Basically, you can pass
I'm really looking forward to have MathUnit integrated, there are more and more issues that will be solved by MathUnit, it really looks like the way to go 😎 |
Beta Was this translation helpful? Give feedback.
-
Thanks for the clear explanation. I'll start playing around with it. |
Beta Was this translation helpful? Give feedback.
-
Another thought I had: Would it be possible, or even a good idea, to divide the |
Beta Was this translation helpful? Give feedback.
-
That's an interesting thought. Each of the four implementations will be relatively easy and straight forward to implement. But the downside is that you have to keep four implementations in sync with each other, and there is no way to use your own favourite BigNumber library. If these four implementations have hardly anything in common qua implementation, this makes sense. I have the feeling though that they do have a lot of logic in common, and that the current solution where the actual numeric type and numeric operations are abstracted works nicely. A small experiment to explore your idea can be fun and informative though, it can result in new insights :). |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Finally got the definitions for Whereas the buggy code used the original unitmath instance: 'string': unitmath() The correct code uses the current instance: 'string': (...args) => unitmath()(...args), It's these kinds of bugs that are so difficult to track down which is why I don't particularly like how the interface is shaping up. The UnitMath library is very pure and clean thanks to the many suggestions from @harrysarson. And now in v6, math.js has an amazing dependency injection mechanism. It's just been tricky to get the two to work together. But if we can get it working, we can look at improving the glue between the two libraries later. Next task is to tackle the |
Beta Was this translation helpful? Give feedback.
-
Ah, that makes sense. Good to here you're making progress 👍 Yeah, well it's mostly mathjs to blame. mathjs now is an unideal hybrid between pure functions and a stateful instance. Let's make sure that |
Beta Was this translation helpful? Give feedback.
-
I'm starting work on math.createUnit('foo')
const math2 = math.create()
// math2 should contain foo, but how? Of course, if we could do things over I would suggest making custom units a part of the Another option is we could make custom units part of the config, and just make |
Beta Was this translation helpful? Give feedback.
-
That's good to hear!
|
Beta Was this translation helpful? Give feedback.
-
Oh ok. Then yes that will be much easier!
…On Sun, Aug 4, 2019, 3:17 AM Jos de Jong ***@***.***> wrote:
That's good to hear!
const math2 = math.create() is will not create a full clone of your
current mathjs instance. It will create a completely new instance with
default config. It will not contain any functions you imported using
math.import(...), and I think it should also not contain custom units
created in the initial instance. I think that should make life easy for
unitMath, right?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1551?email_source=notifications&email_token=ABQNHEIWUFJVAESBG3BZEPDQC2NDPA5CNFSM4H4JLCBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3P5WMI#issuecomment-517987121>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABQNHEMQLA5DIND4BRWVQTDQC2NDPANCNFSM4H4JLCBA>
.
|
Beta Was this translation helpful? Give feedback.
-
All right, got Question about |
Beta Was this translation helpful? Give feedback.
-
Woohoo! That's good news 👍 Configuring |
Beta Was this translation helpful? Give feedback.
-
On a side note: in some future version of mathjs (not too soon) I would like to see if we can fully move away from mathjs instances. Currently we have a complicated hybrid between pure functions and a stateful instance. Not sure if feasible and how complicated it will be, I would have to do some experimentation. The simplicity and beautiful API of |
Beta Was this translation helpful? Give feedback.
-
@ericman314 just curious: what is the latest status of UnitMath? Are you still working on it? |
Beta Was this translation helpful? Give feedback.
-
I'm planning to work on it when I have time, so, hopefully soon. What's your timeline for v7? |
Beta Was this translation helpful? Give feedback.
-
Mathjs is on the back-burner from my side these months, I'm working on an other project (jsoneditor). So I think v7 will only contain the new |
Beta Was this translation helpful? Give feedback.
-
Sorry, that was a misclick 😅️ |
Beta Was this translation helpful? Give feedback.
-
UnitMath is now v1.0.0-rc.1, please check it out! https://www.npmjs.com/package/unitmath/v/1.0.0-rc.1 |
Beta Was this translation helpful? Give feedback.
-
Awesome to hear that v1 is close 😎 . I'll have a look soon Eric. |
Beta Was this translation helpful? Give feedback.
-
It's awesome @ericman314 . I left a few minor comments in the repo. |
Beta Was this translation helpful? Give feedback.
-
One of the outstanding items in the Unit.js refactoring is in config changes. I'm looking for some direction and clarification on how to proceed. Mostly I am just finding myself a little behind in understanding all the changes made in v6.
math.config
andmath.create
?Unit.js
, there is an event handler for math.js config changes. If the math.js config mutates, we would be required to create a new instance of unitmath since the configurations in those instances are immutable. What would be the best way to go about doing that?createUnitFunction
is run again? In that case, it would be necessary to read the config when creating the unitmath instance. What is the correct way to do that?createUnit
is called, we will need to create a new instance of unitmath. In the new library, the unit definitions are immutable. Should we handle this the same way we would handle config changes?Beta Was this translation helpful? Give feedback.
All reactions