在rails中保持javascript库最新的最佳方法是什么?

时间:2021-06-16 20:10:25

I am currently develoing a Rails application which makes heavy use of some javascript libraries, including jquery, backbone.js and d3.js. For jquery, there is the jquery-rails gem, for backbone, we have backbone-rails. But nothing like this exists for d3.js.

我目前正在开发一个Rails应用程序,它大量使用了一些javascript库,包括jquery,backbone.js和d3.js.对于jquery,有jquery-rails gem,对于骨干,我们有backbone-rails。但d3.js不存在这样的情况。

I copied the javascript from d3.js to my repository, this feels a bit unclean to me though, because when d3 gets updated, I have to copy it again (and I have to notice, that d3 got updated!). I thought about git submodules, but I have to pull them manually every time I check out the repository. May be there is way to let bundler check out a specific release of the d3 repository?

我将d3.js中的javascript复制到了我的存储库,这对我来说感觉有点不干净,因为当d3更新时,我必须再次复制它(我必须注意到,d3已经更新了!)。我考虑过git子模块,但每次检查存储库时我都必须手动拉它们。可能有办法让bundler检查出d3存储库的特定版本吗?

How do you handle updating third-party javascript libraries in rails? Is there a preferred way?

你如何处理在rails中更新第三方JavaScript库?有首选方式吗?

2 个解决方案

#1


5  

Why not create a d3-rails gem if there isn't one? The convention now seems to be to put these javascript libraries in their own gems with jquery-rails now included in Rails 3.1. It's more work now but it might payoff for you down the road. You would be helping the community and it would make for easy updates within your app.

如果没有d3-rails gem,为什么不创建它呢?现在的惯例似乎是将这些javascript库放在他们自己的宝石中,现在包含在Rails 3.1中的jquery-rails。它现在更多的工作,但它可能会为你带来回报。您将帮助社区,它可以在您的应用程序中轻松更新。

#2


7  

Not sure why you got downvoted for this...

不知道为什么你为此投降了...

But I'm going to have to agree with the comment that says to do it manually. I wouldn't leave it out of your repository - no call for that; you want to keep your current version around - but I'd not recommend having it update automatically.

但是,我将不得不同意手动执行此操作的评论。我不会把它从你的存储库中删除 - 不要求它;你想保持你当前的版本 - 但我不建议自动更新。

That's for stability. If you make "heavy use" of JS like you say, a quirk - or even a bugfix for a bug you worked around - in the latest version of a library could play havoc with your code. We got bit by something like this when jQuery tweaked how it treated attr() and prop() between two versions.

这是为了稳定。如果你像你说的那样“大量使用”JS,那么在最新版本的库中,一个怪癖 - 甚至是你修复过的bug的修正错误 - 可能会对你的代码造成严重破坏。当jQuery调整它如何处理两个版本之间的attr()和prop()时,我们得到了类似的东西。

So if you always update your libraries manually:

因此,如果您始终手动更新库:

  • You always know when they change, and that you have to do some thorough testing before making the changes public.
  • 您总是知道他们何时发生变化,并且在公开更改之前必须进行一些彻底的测试。
  • You can stay with an older version of the library if you want to - for performance, or to give you time to work around the latest quirks, or whatever.
  • 如果您愿意,可以使用旧版本的库 - 为了提高性能,或者让您有时间解决最新的怪癖,或者其他什么。

Hope that helps!

希望有所帮助!

#1


5  

Why not create a d3-rails gem if there isn't one? The convention now seems to be to put these javascript libraries in their own gems with jquery-rails now included in Rails 3.1. It's more work now but it might payoff for you down the road. You would be helping the community and it would make for easy updates within your app.

如果没有d3-rails gem,为什么不创建它呢?现在的惯例似乎是将这些javascript库放在他们自己的宝石中,现在包含在Rails 3.1中的jquery-rails。它现在更多的工作,但它可能会为你带来回报。您将帮助社区,它可以在您的应用程序中轻松更新。

#2


7  

Not sure why you got downvoted for this...

不知道为什么你为此投降了...

But I'm going to have to agree with the comment that says to do it manually. I wouldn't leave it out of your repository - no call for that; you want to keep your current version around - but I'd not recommend having it update automatically.

但是,我将不得不同意手动执行此操作的评论。我不会把它从你的存储库中删除 - 不要求它;你想保持你当前的版本 - 但我不建议自动更新。

That's for stability. If you make "heavy use" of JS like you say, a quirk - or even a bugfix for a bug you worked around - in the latest version of a library could play havoc with your code. We got bit by something like this when jQuery tweaked how it treated attr() and prop() between two versions.

这是为了稳定。如果你像你说的那样“大量使用”JS,那么在最新版本的库中,一个怪癖 - 甚至是你修复过的bug的修正错误 - 可能会对你的代码造成严重破坏。当jQuery调整它如何处理两个版本之间的attr()和prop()时,我们得到了类似的东西。

So if you always update your libraries manually:

因此,如果您始终手动更新库:

  • You always know when they change, and that you have to do some thorough testing before making the changes public.
  • 您总是知道他们何时发生变化,并且在公开更改之前必须进行一些彻底的测试。
  • You can stay with an older version of the library if you want to - for performance, or to give you time to work around the latest quirks, or whatever.
  • 如果您愿意,可以使用旧版本的库 - 为了提高性能,或者让您有时间解决最新的怪癖,或者其他什么。

Hope that helps!

希望有所帮助!