Patch idea for AbbrevsFilter support

69 views
Skip to first unread message

Frank Bennett

unread,
Dec 13, 2016, 5:46:51 AM12/13/16
to zotero-dev
The AbbrevsFilter plugin reads and writes to an SQL database of abbreviations via an extension to the WP citation widgets or the csledit pane.

This poses a problem for Zotero/Juris-M 5.0 citation support, since citeproc-js runs synchronously, wants to fetch abbreviation entries on demand, and database access must now be asynchronous.

In integration.js, citation details enter the processor one by one via a looping call to processCitationCluster() within a function formatCitation(). Since the formatCitation() function is called from within a Promise chain, I've worked out that if formatCitation() is wrapped in a coroutine, we can make a (yielded) async call on the database to load (possibly) needed abbreviations into memory before processCitationCluster() is run. It's a fairly simple fix that avoids the need for (shudder) changes to the citeproc-js internals.

I'll set things up this way in Juris-M, but a similar patch (and a function hook) would be needed in Zotero also, if the plugin is to be used there. Shall I submit a pull request of the changes against Zotero master?

(If the plugin won't be used in Zotero, I might just integrate its code into Juris-M proper, since read/write abbreviation support is essential for legal materials -- but maintaining it as a separate plugin is fine also, if it will find use outside of Juris-M.)

Frank

Message has been deleted

Frank Bennett

unread,
Dec 13, 2016, 6:45:49 AM12/13/16
to zotero-dev
(Oops, sorry. Should have said formatCitation() is called from within an iterator.)

Frank Bennett

unread,
Jan 9, 2017, 11:21:38 AM1/9/17
to zotero-dev
I'm rewriting the AbbrevsFilter to use async database access, and begun testing it with Juris-M 5.0, preloading abbreviation data as described above. Happy to say that it works a treat.

Preloading works fine for all calls to the processor except one. In drag-and-drop, I've discovered that onDragStart cannot be promisified, since that ends up illegally modifying data mid-drag. I think it might be possible to work around that by kicking off an async function that fetches abbreviations from the database before (re)firing a simulated dragStart event that triggers the main event handler code. If it works, I'll put up a PR with the changes, in case it's of interest.

Dan Stillman

unread,
Jan 9, 2017, 2:40:49 PM1/9/17
to zoter...@googlegroups.com
On 1/9/17 11:21 AM, Frank Bennett wrote:
> Preloading works fine for all calls to the processor except one. In
> drag-and-drop, I've discovered that onDragStart cannot be promisified,
> since that ends up illegally modifying data mid-drag. I think it might
> be possible to work around that by kicking off an async function that
> fetches abbreviations from the database before (re)firing a simulated
> dragStart event that triggers the main event handler code. If it
> works, I'll put up a PR with the changes, in case it's of interest.

I'd certainly be interested to know if that works. We ended up
preloading much more data at Zotero startup than we wanted to in order
to have data available synchronously for Quick Copy drag.

Frank Bennett

unread,
Jan 9, 2017, 9:10:12 PM1/9/17
to zotero-dev
This does not bode well.


"Although this interface has a constructor, it is not possible to create a useful DataTransfer object from script, since DataTransfer objects have a processing and security model that is coordinated by the browser during drag-and-drops."

Yet hope springs eternal ...

FB

Frank Bennett

unread,
Jan 9, 2017, 9:48:31 PM1/9/17
to zotero-dev
Confirmed that simulating the event is a no-go. A dragstart can be dispatched on the tree children node, and it triggers the event, but it has not dataTransfer object. If a spoofed dataTransfer object is attached to the event before dispatch, the processes correctly, but the drag does not take effect.

The only hint of an alternative that I've found is this:


Suggestion there is to set a separate cache object, and retrieve it in the drop, and that won't work for a QuickCopy drop into another application. Looks like I'm boxed in, and will have to choose between accepting that QuickCopy cites will not be able to draw on plugin-supplied abbreviations, or loading the entire list whenever the export style is changed. So ... same issue, same options.

Rats. :-)

Frank

Frank Bennett

unread,
Feb 12, 2017, 3:54:56 AM2/12/17
to zotero-dev
To tie this one off, I can report that I did get abbreviations to work in drag-and-drop citations, by preloading abbreviation data that _might_ be used in each item as it is exported to the processor. It requires some additional function hooks in the client code, so the the 5.0 iteration of the Abbreviations Filter will work only with Juris-M. I think I mentioned it before, but if you would like the AF plugin to work with Zotero also, just give a shout and I can work up a pull request.

Frank

Brenton Wiernik

unread,
Feb 13, 2017, 4:09:32 PM2/13/17
to zotero-dev
I personally would like Abbreviations Filter to work in Zotero

Frank Bennett

unread,
Mar 2, 2017, 7:36:49 AM3/2/17
to zotero-dev
The client has pretty well stabilized, and I did an impromptu demo to a student a couple of days ago - which of course threw an error when I switched styles in a document.

It turned out to be a problem with the way I had extended one of the async processing chains inside integration.js -- coroutines and promise chains do not mix well, apparently. I've figured out a solution, though, and it actually behaved as I thought it would (!), so I'm declaring victory and going to bed this evening. :-)

I'll pick out the changes as time permits and try to get a pull request off in the next week or so.

Frank

Emiliano Heyns

unread,
Mar 2, 2017, 11:02:58 AM3/2/17
to zotero-dev
Promises and coroutines ought to work together perfectly - that's what coroutines are for, and whenever I am forced to do async work, I grab coroutines to work with them.

That said, if you're going to do a fair amount of preloading anyway I can heartily recommend lokijs. Spectacularly fast, and no sync issues to deal with. I use it in bbt extensively.

Frank Bennett

unread,
Mar 2, 2017, 4:40:40 PM3/2/17
to zoter...@googlegroups.com
My knowledge of promises, iterators, yield and whatnot  is very incomplete, but my code was definitely broken before, and it's definitely solid now.

Thanks for the tip on lokijs, I'll check it out.


On Mar 3, 2017 01:03, "Emiliano Heyns" <emilian...@iris-advies.com> wrote:
Promises and coroutines ought to work together perfectly - that's what coroutines are for, and whenever I am forced to do async work, I grab coroutines to work with them.

That said, if you're going to do a fair amount of preloading anyway I can heartily recommend lokijs. Spectacularly fast, and no sync issues to deal with. I use it in bbt extensively.

--
You received this message because you are subscribed to the Google Groups "zotero-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zotero-dev+unsubscribe@googlegroups.com.
To post to this group, send email to zoter...@googlegroups.com.
Visit this group at https://groups.google.com/group/zotero-dev.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages