Re-scanning patterns registry breaks select2...or, how does one inject a pattern into the registry from an add-on

I'm working on using mockup via plone.app.widgets 1.x in Plone 4, and trying to make some improvements along the way. I'm stuck with something, though, as an add-on author:

Calling this more than once causes select2 failures on any edit page:

require('pat-registry').scan($('body'))

So the patternslib registry scans things pretty early, and makes it mostly impossible to re-scan your markup after registering a new pattern (from an add-on). So you might as well not bother registering your add-on unless you can figure out how to register it before the registry.init() method is called.

In Plone 5, the plone bundle calls registry.init(); in plone.app.widgets 1.x, the registry.init() is likewise called on load of the widgets.js resource built by mockup (via mockup's 'bundles/widgets.js' bundle). I want to use these stock bundles, but then re-scan after adding my custom widget.

Chicken and egg? How does an add-on author write and deploy a pattern that is not part of mockup, but built using mockup. I want to register my custom widget (extends pick-a-date with improved keyboard input functionality) [1] and rescan pages with date widgets. I want to do this without building a forked bundle of plone.app.widgets. How does one get the sanity of loose coupling here?

Sean

[1] https://github.com/upiq/uu.formlibrary/blob/widgets-work/uu/formlibrary/browser/resources/js/upiq-date-pattern.js#L265

You do not need to manually run the scan again. The registry will automatically scan the DOM with your new pattern after it's registered if scanning has already begun.

There is no need to scan again.

You can also does something like this:

if (!registry.initialized) {
  registry.init();
}

Thanks for clarifying, that seems to jive with what I found here:

So I would just need to do something like this, AFAICT:

require('pat-registry').register(MyPattern, 'mypattern')

Sean