Skip to content
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

Multiple instances of fontoxpath #406

Open
rrthomas opened this issue Aug 19, 2021 · 3 comments
Open

Multiple instances of fontoxpath #406

rrthomas opened this issue Aug 19, 2021 · 3 comments

Comments

@rrthomas
Copy link
Contributor

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.

@DrRataplan
Copy link
Collaborator

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

@rrthomas
Copy link
Contributor Author

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).

@DrRataplan
Copy link
Collaborator

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants