Code Audit #1096
Description
Hey guys, this repo pops up in discussion, and I realize with 400+ issues you are barely able to keep up with the onslaught of issues. I did some poking around and found the distributed un-minified file size is 74kb. That's nearly half of ui-bootstrap's filesize.
I poked around the src files and I have to say I'm completely lost most of the time.
I think (if it's at all possible) it's time to streamline this project and get rid of and merge as many bells and whistles as possible. I realize this is one of the most complex widgets that tend to pop up (aside from a wysiwyg editor or a grid) but if ever there was an opportunity for simplification, this project could merit it.
Not that I have been keeping up-to-date as to the latest trends of the project, but here are some examples:
-
Use flexbox instead of JS sizing the input box.
-
Choice locking? Disabled choices? Choice-related garbage? Nah, lets git rid of all that from the core
-
Implement lifecycle callback hooks:
beforeSelect
,afterSelect
,beforeRemove
,afterRemove
. If we use these, it's ridiculously easy for developers to implement 2 however the hell they want. -
Remove
repeat
attribute (+ the parser)? This may be more difficult, but what if we stop making<select-choices>
represent 1 row and instead put the onus on the developer to handle repeating? What if you had to specify the<ul>
yourself too? No more passing of classes or HTML, no more positioning or styling garbage. No more grouping or sorting or filtering garbage. The user entirely decides what he wants to show on the list, and what he wants to perform when the user clicks on a row. We simply relocate this logic to the templates. -
Sortable should be distributed in a separate file. It should not come with the core. The whole point of repacking sub-features into sub-directives is so that it wouldn't bloat the core, it would reduce filesize, and it would teach / encourage other developers to create their own plugins instead of adding to the 400+ bugs on this repo.
-
Grouping should be a separate file / plugin. If we can't implement it as a plugin, our API needs to be improved.
-
What is this
refresh
stuff? Can't we remove it? -
Get rid of
angular.closests()
. It's not even used in the repo, just in the tests! -
Get rid of
querySelectorAll()
polyfill. It's in all the browsers that count and I don't even think the version of angular we're using supports prior browsers. -
Take highlight out of the core. Make it part of the themes(?). It's a nice feature, but not really super critical and people can implement this however they want to with ease.
-
Add dependency to
ui-position
so we can get rid ofuisOffset
perhaps? I'm on the fence about this one. Technically, you don't even HAVE to position stuff via javascript:<div style="position: relative"> <input /> <ul style="position: absolute; top: 100%; left: 0;">...</ul> </div>
I realize this isn't super amazing calculate side flipping and all that garbage, but make that a separate behavior if at all possible mayhaps?
-
Make
closeOnSelect
get called explicitly inafterSelect
and just let people override it or something? Seriously, lifecycle callbacks ftw. -
No idea what
searchEnabled
is for or why we're watching it. I feel a lot of stuff doesn't need to bewatched
, we could just evaluate these things upon interaction. Are you really going to change the searching ability while the user is in the middle of searching? If some weirdo REALLY wants to, lets expose the API so that it's super easy for them to override this behavior. -
Why are we watching
sortable
too? This doesn't need to be kept up to date constantly, only when the user opens the input I would think. -
tagging
is really just a behavior that happens when the user types in an input. If we have some sort of lifecycle callback whenever the user hitsenter
that simply allows him to push his choice into the list of choices, likeon-select
then we're done. There is no more tagging flags. Same goes for choices, if we let the user render the choices how they see fit, they can specify in the template what 'new' choices look like (or don't). -
taggingToken
could quite literally be anng-keypress
event where the dev is able to explicitly call$select.items.push()
or$select.select('new-choice')
or something. Again, this should be offloaded into a third-party directive as a plugin.
These are just thoughts, and I'm sure I'm a big PITA and half of these aren't actionable, but I'd really like to see this repo get new life, by simplifying it and allowing devs to take their bugs into their own hands.
If anyone would be interested in stepping up and making these changes, feel free to reply!