Replies: 1 comment 5 replies
-
Hey @logaretm thanks for the detailed idea. I think the lib is young enough where we can still somewhat liberally release a breaking change with minimal impact. I think the second approach is better suited, but I'm not afraid to make a breaking change (?) here where we could potentially do something in the lines of:
This will also open up the road for being able to add more stuff to the return of Thoughts? |
Beta Was this translation helpful? Give feedback.
-
What
Following the release of
slotBinds
(#194), It provided a way for plugins to expose state to theSchemaForm
slots.However it doesn't cover most of the needs, some plugins would probably need to also expose a way to mutate their state. This is hard to do in the template, consider the following example where the user would like to reset the form after the submission is processed.
That means in order to do that with the template the user needs to pass the plugins API function as a callback to their own function, resulting in something like this:
This can be fine for some cases but I think it's a little bit unhandy to most. So we need to figure a way for plugins to expose their APIs in the parent's
setup
function with the composition API.How
I tried to think of this in a non-breaking manner, and I got a working PoC, but it has some caveats.
The main challenge here is plugins now to somehow inject their state upwards (towards the parent). Which is the opposite direction of
provide/inject
, this makes it a little bit hard to reason about.Initially, we can re-use
useSchemaForm
and have it return aplugins
reactive object alongside theformModel
.That
plugins
object will be provided to all plugin functions viaprovide/inject
and they can add stuff to it:Eventually it can be used like this:
This is as far as I got the PoC to work.
The caveat here is that the
plugins
are not immediately available within the parent'ssetup
. This is because the plugin function will execute once theSchemaForm
is setup.I can see this being a foot gun even if properly documented. A simple workaround to make it clear to the users is to make it lazily evaluated via a function.
This is just a slight API change that could force users to be more carful around this. I think its hacky tho.
An actual possible workaround is to use something different than
useSchemaForm
, perhaps a similarly named function created bySchemaFormFactory
.This would allow plugins to "prepare" dummy values initially that can be used until the form is setup. Sounds hacky but it move this responsibility to plugin authors which I would agree are more likely to be advanced users than the average and so could take on this caveat.
The usage for the end user looks something like this:
The way this would work, is that the
SchemaFormFactory
will prepare a reactive object for plugins to dump stuff in. Plugins could exposebeforeSetup
method on their return value to allow them to "attach" their state before the user callsuseSchemaForm
.So a plugin fn may look like this:
I probably haven't thought about this enough, LMK what you think!
Beta Was this translation helpful? Give feedback.
All reactions