Closed jgaehring closed 2 years ago
From https://github.com/farmOS/field-kit/issues/493#issuecomment-1059234978:
That last one,
useEntities
, is a Vue "composable", analogous to React hooks, and at the moment I'm leaning most heavily towards this approach to scoping thecheckout
/revise
/commit
functions (#494), which is whatuseEntities
would return.
(Note: I started writing more in that issue, expanding on the pros and cons of putting it on the global lib
namespace, but it seems better to document these ideas here...)
The biggest question is how to expose it. An alternative to the global is to pass them down as provider functions (#485), so I could track which module made a particular call to checkout
or commit
etc. That could be useful for implementing a "backup" mechanism that can isolate uncommitted revisions to a single module and store them separately, so if/when they are retrieved they don't end up munged together with revisions from other modules.
I'm wondering now, though, if it might just be possible to have a useBackup
to create a separate bit of state that can be passed in as an option to either useEntities
or checkout
or both. So something like this:
const backup = useBackup({ key: 'tasks-edit' });
const options = { backup };
const { checkout, revise, commit } = useEntites(options);
// And maybe even provide that backup instance with a method like this...
const uncommittedChanges = backup.recall('log', type, id);
I kinda like that. I haven't thought about all the implementation details but it seems perfectly doable. And it creates a nice pattern of favoring standalone utilities like that, rather than dumping everything into providers.
That could be useful for implementing a "backup" mechanism that can isolate uncommitted revisions to a single module and store them separately, so if/when they are retrieved they don't end up munged together with revisions from other modules. I'm wondering now, though, if it might just be possible to have a
useBackup
to create a separate bit of state that can be passed in as an option to eitheruseEntities
orcheckout
or both. [...] [I like how] it creates a nice pattern of favoring standalone utilities like that, rather than dumping everything into providers.
I'm thinking even more about this and how it all interrelates to what is provided to modules and how different actions can be attributed to them. I started to propose introducing some kind of identifier to every module, via provide/inject, but I keep forgetting that modules already have a de facto identifier in the form of the current route, which must be tied to a unique module as defined by the routes
object included in their module.config.js
. For issues like the backup, this could be accessed via useRoute
at any time during the execution, and could in fact be even more useful since it will also indicate the precise nested route where the revision was checked out.
Just including the docs from Orbit.js, brought to my attention by @mstenta via @symbioquine:
https://orbitjs.com/docs/getting-started
Looks like I might have replicated some of what this library does here, but I'm pretty far along at this point and I don't want to rip it all out just now, since I don't think it'd be a simple plug-and-play solution. That said, I can totally see how it might be worthwhile revisiting this once I have a better idea of the trade-offs, or if we find a more robust implementation is needed.
This draws on some ideas formed, and conclusions arrived at, in two previous issues:
274
485
It's probably best summed up in https://github.com/farmOS/field-kit/issues/274#issuecomment-1008008036: