-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Separate Mn DOM interaction into a mixin for DOM plugin ease. #3145
Comments
Yep I think it's be amazing to have a plugin API.. totally spitballing here.. but something like: import vanillaJsPlugin from 'marionette-vanillajs';
// sets the default
Mn.setDomPlugin(vanillaJsPlugin);
/// Then later
/// There's one particular view I want another DOM plugin for
const MyView = Mn.View.extend({ ... });
// Where the jQueryPlugin ships attached to Mn as the default
// Default until it isn't the default in Backbone.
MyView.setDomPlugin(Mn.jQueryPlugin); |
I was thinking more in the lines of import myDomMixin from 'myDomMixin';
const MyBaseView = Mn.View.extend(myDomMixin);
// or const MyBaseView = Mn.View.extend(_.defaults({/*stuff for my view*/}, myDomMixin)); It's more explicit opt-in Although I imagine MyView.setDomPlugin(Mn.jQueryPlugin); would internally look like setDomPlugin(plugin) {
_.extend(this.prototype, plugin);
} It's almost looking like |
It would be a very specific mixin. There was a similar conversation involving replacing the renderer in particular (which is still an idea I'm for) And that's where using a static function for configuration came up for me. What I like about it.. is you can change all |
Based on the comment link, I can see it working there since its one change. MyView.setDomPlugin({
replaceChild() { /* no replacing */},
appendChild() { /* no appending */}
}); But I am guessing the responsibility is left up to the hypothetical VDOM plugin author to do the work while the Mn user would just import and set or just import if the author has an implicit apply. So... 👍 to get DOM mixin for now? |
A yes for sure. 👍 abstracting everything for a mixin is great now. But yeah I think the API I'm suggesting would be more for external plugins that handle the entire API. Like we'd provide an empty template for making DOM plugins. I don't necessarily know why users couldn't just extend a few functions one-off for a particular view. But there'll be caveats to changing some functions.. and hopefully plugins can handle or at least better document how things change if you use a different Dom plugin. |
this would be so useful for my native plugin I am working on!! |
yeah, I thought about that also. But I can't fix your non-$ |
next...rafde:DOM-mixin start I might have to override _setAttributes maybe _ensureElement https://github.com/jashkenas/backbone/blob/96e94b3b6cc26aae190aa0a136037d729e3afa21/backbone.js#L1449 trying to draw a line. |
I don't think anyone can fix that issue :( I think it will just need On Wednesday, August 31, 2016, Rafael De Leon notifications@github.com
|
made some more updates in the PR. I think I am done relative to Marionette's explicit usage of |
Separate Mn DOM interaction into a mixin for DOM plugin ease.
If you want to add a VDOM system or don't want to use jQuery, there isn't an easy way to override DOM interacting functions.
Expected behavior
Provide an easy way to find functions that do DOM interaction in order to override them.
Place all DOM interacting functions into a mixin that can be used to reference for overriding for plugin needs.
example
backbone.marionette/src/region.js
Lines 178 to 184 in 8604cd1
backbone.marionette/src/region.js
Line 200 in 8604cd1
would be replaced by a function from a mixin that looks like
Now you can override
appendChild
andreplaceChild
for VDOM usage.this idea came from #3082 (comment)
Environment
The text was updated successfully, but these errors were encountered: