未加星标

Ember Life without jQuery

字体大小 | |
[前端(javascript) 所属分类 前端(javascript) | 发布者 店小二04 | 时间 2019 | 作者 红领巾 ] 0人收藏点击收藏

Starting with Ember 3, the steps to remove jQuery as a dependency have begun. After doing some transition work with a few of our larger components, I’ve noticed a few things that might come in handy for anyone else updating their work. All of these should work in 2.18 and will help smooth final transitions you may make in 3.x.

Tests

I would definitely say tests are where the majority of the jQuery you use will exist. Fortunately, we’ll get a lot of help on this one thanks to a codemod . The codemod is basically a little set of scripts that will do a ton of the conversion work for you, updating a lot of your tests to use the newer Ember Test Helpers . Depending on the complexity of your tests, this could very well cover everything, however you may find yourself hunting down jQuery methods trying to run off the native HTML objects and failing. I like to use a combo of You Might Not Need jQuery and DevDocs to help hunt down the correct equivalents of anything the codemod may have missed.

$

I believe if you search for $( , you will be able to find all the manual jQuery you have sprinkled throughout your code. At which point, you can use the previous 2 links to help you convert jQuery code into vanilla JS. This code seems to generally appear in one/some of the life-cycle hooks of the component. This is generally a straight forward process, depending how comfortable your are with vanilla JS. Some more complex .ajax calls did need some extra referencing. This post , along with this one , may help you in converting them into a native XMLHttpRequest .

Add-ons

This is where things might get tricky. Hopefully you do your due diligence and keep your add-ons as up to date as you can, unfortunately sometimes you’ll find that there’s been a major release that changes a good amount of code and the upgrade effort jumps dramatically. I noticed this happen on our side with Ember Test Selectors . We’ve been using an older version in our style guide and they’ve updated one of their major syntax styles to which we had unknowingly missed, and have already used across other applications. That means in order to use the newest test selector package, we also have to update a lot of test code manually , in all the different places we’re still using the older style. Depending on which add-ons you use, you might even find yourself in a spot where you realize it’s not even being maintained anymore or hasn’t received any updates yet. This is definitely a good time to assess your package tree and make sure you are depending on stuff you need and that is maintained, otherwise it may be wise to switch packages or write your own code!

Other

As far as I’m aware, that about covers all your bases. If you are using Ember Data, you’ll need to swap in ember-fetch to opt out of the jQuery needs. If you’re not already set up with ESLint, you should do that and make sure you have the ember plugin installed as well, which now has a rule for “no jQuery”. That way, you shouldn’t need to hunt down the $ s manually, the linter can tell you what line and where! Once you’ve cleaned up all the jQuery cruft from your code, you should check out some of the other tweaks and optimizations Ember 3.x can bring to your code.

本文前端(javascript)相关术语:javascript是什么意思 javascript下载 javascript权威指南 javascript基础教程 javascript 正则表达式 javascript设计模式 javascript高级程序设计 精通javascript javascript教程

代码区博客精选文章
分页:12
转载请注明
本文标题:Ember Life without jQuery
本站链接:https://www.codesec.net/view/627951.html


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 前端(javascript) | 评论(0) | 阅读(43)