Skip to content

Removing jQuery from Alert#23596

Merged
Johann-S merged 7 commits intov4-without-jqueryfrom
v4-alert-without-jquery
Aug 23, 2017
Merged

Removing jQuery from Alert#23596
Johann-S merged 7 commits intov4-without-jqueryfrom
v4-alert-without-jquery

Conversation

@Johann-S
Copy link
Copy Markdown
Member

I'm near the end for this plugin

The last thing I have to fix is :

  $(document).on(
    Event.CLICK_DATA_API,
    Selector.DISMISS,
    Alert._handleDismiss(new Alert())
  )

And how folks will user our plugins without jQuery, maybe we should enable to register our plugins to jQuery even if we do not use it anymore 🤔

Work in progress...
@XhmikosR if you want to help me do not hesitate 😄

@Johann-S Johann-S force-pushed the v4-alert-without-jquery branch from 448b4a9 to 2a5a34d Compare August 21, 2017 14:25
@Johann-S Johann-S force-pushed the v4-alert-without-jquery branch from 8e1d401 to 96e025c Compare August 21, 2017 14:51
@Johann-S
Copy link
Copy Markdown
Member Author

It seems on Windows 8 and 8.1 for IE10 and IE11 CustomEvent produce errors 😢I'll add a polyfill

@Johann-S Johann-S force-pushed the v4-alert-without-jquery branch from 2c0c0d4 to 28b8564 Compare August 21, 2017 17:50
Comment thread js/src/dom/selectorEngine.js Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should have a find method for querySelector? It should be faster than querySelectorAll especially if we know we want one element.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, what do you think about adding helper methods around qsa, qs, etc? Instead of us calling the whole thing across the codebase this should result in shorter minified code.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a findOne method should be a good thing with querySelector and why not adding helpers methods but I prefer longer method because it's simple to know what they do

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any ideas why it failed on IE ? I added a CustomEvent polyfill

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think we should have our helpers around qsa, qs, etc. The minified code will be a lot shorter that way. We can still name them Util.getElementById etc.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should make a PR when this one will be merged 👍

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try locally with IE?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found on my local IE thanks 👍 btw I hate to debug on IE 😢

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Johann-S: maybe we could make find accept an element parameter and if missing use document?

Regarding findOne since we already have a function I think it might be better if we just filter the selector and if it's one then call querySelector. For all this we should do some benchmarks because I'm not sure if it's worth in this case. If we called it directly it should be faster for sure.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I agree for your two proposals 👍

@Johann-S Johann-S force-pushed the v4-alert-without-jquery branch from 28b8564 to 9b65b23 Compare August 21, 2017 20:09
@Johann-S
Copy link
Copy Markdown
Member Author

I win against IE 💪 😆

@XhmikosR
Copy link
Copy Markdown
Member

XhmikosR commented Aug 21, 2017 via email

return null
}

let selectorType = 'querySelectorAll'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After looking into this file I still believe we should have a wrapper generic function and instead do what I suggested and just provide qsa, qs, etc. It's one less thing for the engine to do so it should be as fast possible.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not against it but that's not something to prioritize here we should focus on event namespacing

Comment thread js/tests/unit/alert.js
var $alert = $('<div class="alert"/>')
$alert.appendTo('#qunit-fixture')

EventHandler.on($alert[0], 'close.bs.alert', function (e) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, things still work fine with jQuery?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep everything is fine

Comment thread package.json
"js-lint-docs": "eslint --config js/tests/.eslintrc.json assets/js/",
"js-compile": "npm-run-all --parallel js-compile-*",
"js-compile-bundle": "shx cat js/src/dom/event.js js/src/util.js js/src/alert.js js/src/button.js js/src/carousel.js js/src/collapse.js js/src/dropdown.js js/src/modal.js js/src/scrollspy.js js/src/tab.js js/src/tooltip.js js/src/popover.js | shx sed \"s/^(import|export).*//\" | babel --filename js/src/bootstrap.js | node build/stamp.js > dist/js/bootstrap.js",
"js-compile-bundle": "shx cat js/src/dom/eventHandler.js js/src/dom/selectorEngine.js js/src/dom/data.js js/src/util.js js/src/alert.js js/src/button.js js/src/carousel.js js/src/collapse.js js/src/dropdown.js js/src/modal.js js/src/scrollspy.js js/src/tab.js js/src/tooltip.js js/src/popover.js | shx sed \"s/^(import|export).*//\" | babel --filename js/src/bootstrap.js | node build/stamp.js > dist/js/bootstrap.js",
Copy link
Copy Markdown
Member

@XhmikosR XhmikosR Aug 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just thinking out loud: this is getting too big. Would it be possible to move this outside of package.json maybe to an external json file file or something?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that would be better if we have other file to add

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but this is just planning ahead. We'll definitely need it and this just seems like bad planning to me.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With my PR which improve our modularisation I introduced a bundler (Rollup) which handle that pretty well

@Johann-S Johann-S force-pushed the v4-alert-without-jquery branch from b353ca1 to e9b95e9 Compare August 23, 2017 09:06
@Johann-S Johann-S force-pushed the v4-alert-without-jquery branch from e9b95e9 to 438f06b Compare August 23, 2017 09:22
@Johann-S Johann-S force-pushed the v4-alert-without-jquery branch 2 times, most recently from 87dd8dd to b91d0c8 Compare August 23, 2017 10:29
Comment thread js/src/alert.js Outdated

if (selector) {
parent = $(selector)[0]
const tmpSelected = SelectorEngine.find(selector)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this temp var?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No we can remove this var 👍

Comment thread js/src/alert.js
// static

static _jQueryInterface(config) {
return this.each(function () {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder how this still works. each is jQuery specific, isn't it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but this method is called only when jQuery is present

@XhmikosR
Copy link
Copy Markdown
Member

XhmikosR commented Aug 23, 2017 via email

@Johann-S Johann-S force-pushed the v4-alert-without-jquery branch from b91d0c8 to f862b8e Compare August 23, 2017 13:58
@Johann-S Johann-S merged this pull request into v4-without-jquery Aug 23, 2017
@Johann-S Johann-S deleted the v4-alert-without-jquery branch August 23, 2017 14:05
@Johann-S Johann-S mentioned this pull request Aug 23, 2017
45 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants