-
-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
plugin system for external npm dependencies #227
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for exploring this idea!
I'm wondering if it would make more sense to rename the current morph
operation to morphdom
and rewrite the morph
operation to delegate the operation call to the configured morph-library.
I was thinking something along the lines of:
import CableReady from "cable_ready"
CableReady.initialize({ morph: "morphdom" })
And then the morph
operation is doing something like:
morph: operation => {
CableReady.operations[CableReady.config.morph](operation)
}
This would also allow you to configure CableRady if don't want to use any morph-plugin at all:
CableReady.initialize({ morph: "innerHtml" })
Great suggestions, @marcoroth. I like the idea that there could be a dominant morph method set. Lemme take a pass at seeing how I can make this work. One thing I'm trying to decide is whether to refactor the current I suppose I already know the right answer, it's just a "do the work" thing. 😸 |
I am struggling with this in some ways, though. I have a few goals:
Currently, I feel like the best plan for someone using CR is to be explicit in their choice of operation. Having to configure a favorite introduces a factor for someone else to change this value and mess everything up, and for not a lot of value. Trying to explain this scheme might prove quite challenging, too. Also, having these pointers to other methods creates a lot of potential confusion wrt the events that are raised. If you call a I think I would be a lot happier with someone just calling the operation that they want, and getting back the events that they expect. We've already done the work to support this on the SR side, via the Still thinking through everything. |
While I don't think having
Yeah I think that makes sense, but on the other hand we should let it default to something if they don't want to decide which morph library to use.
In this case it could call both. First On the SR side, |
I'm not sure that I follow; the intention of the Plugins mechanism is that it can be anything. If you look at the README, I tried to explain:
What this means is that someone could distribute a package of CableReady custom operations, and those operations could call upon Plugins so that they don't have to bundle every library those operations require. For example, someone could release a package of audio operations, which each use different audio-related npm packages.
That's what I've done. I believe that our goal should be to nudge people away from using a
After this PR is merged, SR will default to |
Type of PR (feature, enhancement, bug fix, etc.)
Enhancement?
Description
This PR introduces a general plugin store (
Plugins
) mechanism that can be easily accessed by new and existing operations.morphdom remains a dependency and is automatically registered as a plugin for v5 to ease transition.
The initial motivation was to create a path towards having access to newer alternatives to
morphdom
, including: idiomorph, micromorph, nanomorph, diffhtml, @alpinejs/morph and diffDOM, as well as likely more to come.However, this implementation allows developers of custom CR operations to register any arbitrary library and access them via the same
Plugins.foo
mechanism.I duplicated the
morph
operation to a new operation calledmorphdom
, with the goal and intention of deprecating themorph
operation in a future release.morph
now raises a deprecation warning in the console, and SR will be updated to default to usingmorphdom
as the morph operation.If someone attempts to use an operation that requires a plugin which has not been registered, it will log a console error stating that the required plugin has not been registered but other operations will continue without interrupting the control flow.
Tasks
morphdom
operation as the default morph operation instead ofmorph
, including the example code in the initializer generator.app/javascript/config/cable_ready.js
as per the example above.idiomorph
,nanomorph
and@alpinejs/morph
akaalpine_morph
, pending discussion; we might simply offer code snippets in the docs instead of creating new operations. Update: will do this as a separate PR.Why should this be added
Zero dependencies + shave 2.1k off the bundleDecided to keep morphdom as a dependency for v5 for a smoother rollout and transitionmorph
methodChecklist