fontoxpath icon indicating copy to clipboard operation
fontoxpath copied to clipboard

Multiple instances of fontoxpath

Open rrthomas opened this issue 4 years ago • 3 comments
trafficstars

I would like to be able to have multiple instances of fontoxpath, but this doesn't appear to be possible at present: for example, registerCustomXPathFunction affects the global state. See #398.

rrthomas avatar Aug 19 '21 07:08 rrthomas

Hey Reuben,

This would indeed be very useful. We are working on a project in Fonto that will bring this, but I cannot give a clear timeline when we are shipping this.

For context: right now, a Fonto editor will globally declare a prefix (ie db) to a URI ( ie. the docbook URI). This causes problems when we have a generic piece of code that ties that same arbitrary prefix to another URI. The same of course applies to functions. We are planning to make separate 'instances' of the XPath engine that are fully distinct. We will then be able to 'tie' XPath scripts to these instances to remove the global namespace registration, any global functions, etcetera.

This is a big refactoring that will likely cause breaking API changes (or imho be a good reason to finally break some APIs to simplify them).

Long story short: we are planning to work on this, no timeframe yet.

Thanks!

Martin

DrRataplan avatar Aug 20 '21 11:08 DrRataplan

Thanks for the update, @DrRataplan! I don't know if it would be easier, but simply being able to reset fontoxpath's global state would be helpful; for example, in writing tests (where it would be nice to be able to reset the state between each in a series of tests).

rrthomas avatar Aug 23 '21 12:08 rrthomas

Cool. That would be something that can be implemented relatively easily. We currently have global state in declared functions, declared modules, and something in namespaces where undeclared prefixes will sometimes generate their own URI. Backwards compatibility from when we did not understand namespaces yet...

This will also make a lot of tests a bit easier to write (just a fontoxpath.resetGlobalState() call in an afterEach on the global level).

DrRataplan avatar Aug 23 '21 12:08 DrRataplan