I’d like to contribute an idea for a container ottype that delegates all of the work on designated keys to other ottypes. Something along the lines of factory for creating a type to house rich-text, text, simple scalar values, or any other data type. I’d appreciate feedback on this idea and details below.
The main export of this new library would be a function that accepts a mapping of keys to type names, and returns an ottype object that delegates the internals of create(), apply(), transform(), and compose() to the specified child types, e.g.
BlogPost = makeType({ title: 'text', body: 'rich-text' })
I’m thinking that a snapshot of this type would be an object with only the keys known to the type, with values corresponding to the child type’s snapshot format, e.g.
{
title: 'my versioned blog post title', // text
body: { ops: [{ insert: 'my versioned blog post body' }] } // rich-text
}
And similarly, an op of this type would be an object with only the keys known to the type, with values corresponding to the child type’s op format, e.g.
{
title: [3, { d: 10 }, 'changed'], // s/versioned/changed/
body: { ops: [{ retain: 3 }, { retain: 3, { attributes: { bold: true } }] } // bold 'versioned'
}
With these definitions, I think there are straight forward implementations of create(), apply(), transform(), and compose().
As you can see from my examples, my use case if for versioning all the various fields of a blog post in a unified way, storing the composite snapshot values in my database as JSON. (I’m not using ShareJS, but a home-grown solution using ottypes).
Do you think this is a good idea?
There is a rabbit hole to fall down here, where a JSON ottype could be implemented using this scheme. All that would be required is separate types to delegate handling of JSON arrays and scalar values. If you wanted an open-ended data type, you could specify a default sub-type for added keys along with some convention for deleting keys.
I think having separate ottype implementations for vectors, sets, and maps (JSON arrays and objects) sounds compelling, rather than having all of it wrapped up in the JSON ottype. Is this worth exploring?
I'm just starting to write some of these ideas down in code, but wanted to check with the group to validate some of my ideas before I got too deep.
Thanks for any and all input!
--
You received this message because you are subscribed to the Google Groups "ShareJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sharejs+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.