okfn/annotator — pull request #277 by nickstenning (2013-11-02 22:01:04+00:00)
Title: Replace Store persistence management with the Registry

This pull request takes the persistence logic that was up until now somewhat messily split between core Annotator and the Store plugin, and moves much of the hard work (annotation lifecycle management) into an intermediate class, the Registry.

The annotation registry exposes five methods: create, update, delete, query, load. Each of these methods calls the appropriate hooks (such as `beforeAnnotation{Created,Updated}`) at the appropriate time, and passes a serialized representation of the annotation (or query, in the case of "load" and "query") back to the store plugin, which can now focus on persistence, without having to worry about the intricacies of adding and removing highlights, etc. (An example alternative store plugin, useful for testing, is also added: `NullStore`.)

All a store plugin now needs to implement are the four methods: create, update, delete, and query (the registry's "load" is merely a simple wrapper around the results of a "query"). Each method returns a promise that can either resolve to the created/updated annotation, or be rejected due to errors. Error handling and reporting is only sketched out in this pull request, and will need further attention.

Some plugin functionality may well have been broken by these changes. We will need to do a full review of test coverage and suitability before releasing any of this work.