jsep icon indicating copy to clipboard operation
jsep copied to clipboard

Multiple instances of jsep with different operators

Open cmarcao opened this issue 3 years ago • 5 comments

Hi guys.

There is any reason to have a singleton parser? There is no chance to have more than one jsep with different configuration running in the same app at client side?

Thank you,

Carlos Marcão

cmarcao avatar Feb 07 '22 18:02 cmarcao

@EricSmekens and @LeaVerou - any thoughts on this? I know when we first started moving into a plugin system, this was discussed, but then dropped to reduce complexity/scope. I feel like this could be useful in some cases and could be re-done similar to what this commit removed?

6utt3rfly avatar Feb 28 '22 02:02 6utt3rfly

Any proposal for additional complexity should be justified through use cases. What are the use cases for having multiple parsers with different configurations and how common are they?

LeaVerou avatar Feb 28 '22 15:02 LeaVerou

@LeaVerou I would like to use jsep in a library with a custom binary operator but I cannot because of the singleton nature of it might lead to transient, hard to locate bugs

joeflateau avatar Jul 29 '22 20:07 joeflateau

I think what @joeflateau said sums it up for me. If writing an application, then the singleton nature most likely isnt an issue.
But if writing a library, it could be an issue if some other component of the application also uses jsep.

I was considering using this for an application, where I would want to be able to parse boolean expressions and number expressions separately under different rules. While I could manage with this singleton, it would require swapping out the acceptable operators and things each time I want to parse an expression, which is rather wasteful.

Julusian avatar Dec 23 '22 19:12 Julusian

related to #28

jdanyow avatar Jul 29 '23 18:07 jdanyow