On Feb 17, 11:51 am, FND <f...@gmx.net> wrote:
> Martin and I are working on a TiddlyWeb store to simplify TiddlyWiki
> plugin development in conjunction with TiddlyWeb.[1]
>
> While we're making good progress, it might be useful to have a generic
> overview of the StorageInterface's various entry points.
See StorageInterface definition [1], that is the canonical definition
of the interface, including only those methods which matter to the
interface. That should be your _formal_ starting point for
understanding the interface. Obviously as text is the main
implementation it makes for a good reference, but as you say, it is
quite noisy and confusing.
> As far as I can tell, this is what a store needs:
> * get list of items (bags/recipes/users or tiddlers/revisions)
> * put/get/delete item (bag/recipe/user or tiddler[2]/revision)
> * search (optional?)
Officially it is all optional. If you look in tiddlyweb/stores/
__init__.py you'll see that everything raises
StoreMethodNotImplemented. If your store implementation doesn't
implement something that's what will happen. This is used, for
example, in the googledata store to support not doing revisions.
But yes, that is the basic list.
> As I understand it, the respective store implementation needs methods
> named according to the established convention - namely:
> * list_<item>
> * <item>_<put|get|delete>
>
> Is this correct? Anything I'm missing?
That's not quite correct, and there's an important distinctions.
<item>_{put,get,delete} is correct, but it is list_<item>s. That
plural-ness is relevant.
tiddlyweb.store does automatic dispatch for put, get, delete because
it can do a one step introspection of the object passed to store.
{get,put,delete}. Those are actions on singular objects. The list
methods do not accept any singular object as input and return a list.
To do introspection you would have to pass in a type of some sort that
just gets tossed away. To me this would make the calling code
dishearteningly confusing and create an idiom that is linguistically
awkward.
get(bag)
makes some sense, but
list(recipes)
would really only make sense if we had previously created a recipes
list of some kind and that's what we're trying to do with the call
anyway, so...?
And, list() is already in use in Python anway.
> However, the text store implementation seems much more complex at first
> glance. Perhaps that's because there's a separate (though almost
> identical) bunch of methods for each of the items mentioned above?
Much of the semi-identical code is intentional. When I write code a
first time I will leave the pseudo-duplication in place to better
understand the problem. If the duplication becomes an issue I'll clear
it out. Right now you can look at that duplication and think: wow you
know, all this stuff is really kind of the same (read in some content,
deserialize it; serialize some object, write it out).
> How about refactoring that interface to use something like list(type)
> and <put|get|delete>(mode, type), with the respective type-specific
> functionality delegated to private methods (if required)?
What is "mode" in your text above?
Like with much of the stuff going on in TiddlyWeb, the
StorageInterface is at is to make side A of the code stay the same in
the face of changes on side B and to make the responsibilities of side
B as explicit as possible. This often means that both sides might
initially be a bit more fluffy than you really like, but over the long
run tends to be useful. As long as the interface between A and B is
tight and clean its a win. This is the same principle that drives the
web.
You'll note that for calling code (the stuff in TiddlyWeb that uses
things that implement the StorageInterface) it is not the
StorageInterface itself that is called. It's the interface of
tiddlyweb.store. That module provides a layer of indirection into the
StorageInterface. It abstracts that interface for the sake of
reasonable idioms for the caller while allowing StorageInterface to be
(what might be to you too) explicit. Both of those things help me as
the developer to know, clearly, in any particular domain what I need
to do to write code. Because stores are something I expect people to
write lots of, the method names in it are highly descriptive and (at
least to you) fairly redundant.
I hope this makes some sense. I can try to be more clear if you've got
more questions.
[1]
http://trac.tiddlywiki.org/browser/Trunk/association/serversides/tiddlyweb/core/tiddlyweb/stores/__init__.py
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TiddlyWikiDev" group.
To post to this group, send email to TiddlyWikiDev@googlegroups.com
To unsubscribe from this group, send email to
tiddlywikidev+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/TiddlyWikiDev?hl=en
-~----------~----~----~----~------~----~------~--~---