-
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
Deprecate region @ui selectors #3497
Comments
I would deprecate UI stuff as a whole or at least its usage in events / triggers keys. Its concept is tied to jQuery way of manipulating DOM, that's not as ubiquitous as used to be. In my apps, even the ones that i use jQuery to manipulate the DOM i dont use UI |
hmm I've used |
What I would support in the near future is putting the |
This is an interesting debate because I guess different people use In my case I make heavy use of it (including to mark the regions). I use it to distinguish beetween parts of the template that must not be touched when the template is changed, otherwise the view will not work as expected. I can look at it and know immediatelly if it's safe to change some part of the template. So I fully agree with keeping the |
Thanks for the input. I think I agree. The unfortunate part of the region @ui is that it somewhat complicated and might be at unfortunate spots (as it has to search each region string per render regardless of if you use the feature) |
I also use Removing it only for region is not consistent and maybe to soon. Another move would be to upgrade the way regions are used / declare, and after the new alternative is accessible, shutting down the old way. |
It's worth noting that @ui was around for triggers and events for a lot longer than for regions. const normalizeUIKeys = function(hash, ui) {
return _.reduce(hash, (memo, val, key) => {
const normalizedKey = normalizeUIString(key, ui);
memo[normalizedKey] = val;
return memo;
}, {});
}; And here's the code only used for regions: const normalizeUIValues = function(hash, ui, properties) {
_.each(hash, (val, key) => {
if (_.isString(val)) {
hash[key] = normalizeUIString(val, ui);
} else if (_.isObject(val) && _.isArray(properties)) {
_.extend(val, normalizeUIValues(_.pick(val, properties), ui));
/* Value is an object, and we got an array of embedded property names to normalize. */
_.each(properties, (property) => {
const propertyVal = val[property];
if (_.isString(propertyVal)) {
val[property] = normalizeUIString(propertyVal, ui);
}
});
}
});
return hash;
}; And all of that code in v3 currently runs against I think other selectors such as I am also concerned that needing to support this will make changing how regions work for v5 more difficult, and I think we can provide better ways to let users reuse ui elements for a region if need be.. but I'm still wondering considering |
That's a fair and heavy point. So what the plan would be ?
|
After feedback from the community I think the feature flag is ideal, but I would divide triggers/events Then I am going out on a limb here, but I think v4 should possibly introduce a |
With #3537, only The only problem is that will change the signature of a public method although a not documented one. Also i don't see many use cases for it |
I think we should likely privatize |
I m using it to normalize |
What method do you use?
Can you post a snippet of the code? |
Here's our usage for stickit(). We probably have 800 source files dependent on this. #-----------------------------------------------------------------------------#
# Imports
#-----------------------------------------------------------------------------#
import _ from 'lodash'
import Marionette from 'backbone.marionette'
#-----------------------------------------------------------------------------#
# Turn off the childViewEventPrefix feature.
#-----------------------------------------------------------------------------#
Marionette.setEnabled 'childViewEventPrefix', false
#-----------------------------------------------------------------------------#
# Save original Backbone.Stickit functions and the destroy function.
#-----------------------------------------------------------------------------#
stickit = Marionette.View::stickit
addBinding = Marionette.View::addBinding
unstickit = Marionette.View::unstickit
destroy = Marionette.View::destroy
#-----------------------------------------------------------------------------#
# Stickit selectors can be hashes, strings, or undefined. We need to
# normalize each type.
#-----------------------------------------------------------------------------#
normalizeSelector = (selector, view) ->
return switch
when _.isObject selector then view.normalizeUIKeys selector
when _.isString selector then view.normalizeUIString selector
else selector
#-----------------------------------------------------------------------------#
# Shim the three standard Stickit calls into Marionette View objects so
# that we can use the @ui syntax for bindings; this eliminates repetition of
# possibly long and complex selectors and allows us to have one definition
# for them, in the ui hash or function for the View. We also need to patch
# the destroy function, as the remove method that's patched by Stickit is
# never actually called by Marionette.
#-----------------------------------------------------------------------------#
_.extend Marionette.View::,
stickit: (optionalModel, optionalBindings) ->
return stickit.call @,
optionalModel,
@normalizeUIKeys(optionalBindings or _.result(@, 'bindings') or {})
addBinding: (optionalModel, selector, configuration) ->
return addBinding.call @,
optionalModel,
normalizeSelector(selector, @),
configuration
unstickit: (optionalModel, optionalSelector) ->
return unstickit.call @,
optionalModel,
normalizeSelector(optionalSelector, @)
destroy: ->
@unstickit() unless _.isEmpty @_modelBindings
return destroy.apply @, arguments
#-----------------------------------------------------------------------------#
# Exports
#-----------------------------------------------------------------------------#
export default Marionette
#-----------------------------------------------------------------------------#
|
Yep notably missing |
You're right, mostly using |
With upcoming changes to region I believe |
Regions can currently use the
@ui
selector for their el selector.This I believe is a rather expensive lookup that is only used for regions found here:
https://github.com/marionettejs/backbone.marionette/blob/master/src/mixins/ui.js#L25
This provides limits usefulness while requiring an expensive process. In the future I think regions may perhaps be able to be defined with a view's ui element directly if need-be, but we should remove the
@ui.
helper here.The text was updated successfully, but these errors were encountered: