For CryptPad and the realtime infrastructure we deal with a DOM structure and we needed to do a similar thing (for example to remove elements which are part of the editor and not the document). We opted to use a similar strategy using filter callbacks but we don't have lookahead capability.
Example Filter: https://github.com/xwiki-labs/cryptpad/blob/master/www/pad/main.js#L51 Scanning the DOM while filtering: https://github.com/xwiki-labs/hyperjson/blob/master/hyperjson.js#L34 For your use case you might consider to allow for buffering elements in a queue for lookahead, your API might look like: public void filter(Event ev, Callback<Event> whenDone); Since you don't need to return the element synchronously, you can buffer a bunch of events inside of the filter and wait until you know what to do and then send them all in a loop. Anyway just an idea. Caleb On 06/07/16 22:33, Vincent Massol wrote:
Hi devs, Rendering Tx are great to modify an XDOM into another XDOM. However they have a limitation: they’re slow (since you have to traverse the whole AST). So if you have 10 Tx, you traverse the AST 10 times… I’d like to brainstorm about an alternative: the ability to register some Listener that will get executed at render time and that will transform the events. Use cases ======== Here are some example of Tx that would benefit being rewritten using this mechanism: * Icon Tx * Auto linking of JIRA id to jira issues * WikiWord Tx Implementation ============= It could be something like: * Introduce a ConfigurableBlockRenderer interface with a addListener() method * Modify AbstractBlockRenderer to execute those Listeners before it calls its PrintRenderer. This can be achieved with a composite listener that wraps the listeners added and the PrintRenderer. * Have a way to register some Listeners in the configuration, that should be executed when a page is rendered * Modify XWikiDocument so that those configured listeners are executed when rendering a page Differences between Tx and Listeners ============================== * Tx are slow but easy to write since you have access to the whole AST * Listeners are harder to write since you need to store the events if you need to remember them (but we have developed some tools already over the years such as the LookaheadListener) * Listeners depend on their order and they should be written carefully to minimize their interdependencies * Listener will get executed only at render time so you need to render to get the modifications to the tree, while Tx are independent of rendering. WDYT? Do you see a better way to achieve the same goal (ie removing the Tx performance limitation)? Thanks -Vincent _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs

