On Tuesday 13 May 2014 09:37:28 Matt Quinn wrote:
> Sure. For example, imagine an app that tracks a list of tasks, and the
> user has marked a task complete.
>
> public boolean completeTask(String taskId) {
> Document doc = mDatabase.getExistingDocument(taskId);
> SavedRevision rev = doc.update(new Document.DocumentUpdater() {
> @Override
> public boolean update(UnsavedRevision newRevision) {
> Map<String, Object> props = newRevision.getProperties();
> if (DocUtils.getBoolean(props, "completed")) {
> // This task has already been marked completed by
> // another user -- skip the update.
> return false;
> }
> props.put("completed", true);
> props.put("updatedBy", mUserId);
> props.put("updatedAt", DocUtils.nowDateString());
> return true;
> }
> });
> return (rev != null);
> }
>
> (where DocUtils is a homegrown collection of helpers for stuff we have
> to do all the time, like convert types into/out of documents).
Thank you very much!
Using something like your DocUtils his is exactly the conclusion I have come
to. I will move away from 'proper' domain / business objects in terms of
'static typing' and move to a 'dynamically typed' approach: using Document
objects all around and assuming that the content is what I expect. The
DocUtils will help me doing basic type conversions and the domain specific
classes - just like the static ones in ToDo-lite and your translation objects
- will help me keeping my code readable.
One last question arises: if I have a couple of fields changed, e.g. after the
user edited bis name and birthday and such on a UI screen - how do you avoid
creating revisions for every minor change? Or to put it otherwise: to you
have a pattern / best practice to collate changes while using the helper
classes?
Regads,
Sascha
--
You received this message because you are subscribed to the Google Groups
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/mobile-couchbase/1788239.akpteBujie%40slux.
For more options, visit https://groups.google.com/d/optout.