Open Collective
Open Collective
Loading
cocooned 2.0.0 - The long way out of JavaScript dark ages
Published on March 7, 2023 by Gaël-Ian

That was a long way to go but, after many weeks (months) of work we are really happy to announce the 2.0.0 release of one of our gems: cocooned.

Cocooned started almost 6 years ago as a fork of cocoon, a well known gem to build dynamic nested forms in Rails. The goal at this time was to fix a bunch of long-time issues and add some functionalities, such as support for reordering items and limiting number of items.

Maintaining compatibility with new releases of Ruby on Rails, unit testing parts of the Ruby or the JavaScript code not yet covered, supporting new ways of bundling assets into an application, modernizing development and publishing toolchain… There was a lot to do along these years but we still hadn't had the time for a large cleanup we had in mind.

Cocooned 2.0.0 is a huge refactoring of both Ruby and JavaScript code with some great achievements.

jQuery is not a hard dependency anymore


JavaScript, as a language and as an ecosystem, moved fast in the past years and jQuery is not the main dependency of every new application it was in the past. Cocooned 2.0.0 has been rewritten in plain vanilla JavaScript so it can now be used without jQuery (but still propose an optional integration with it if you really want to).

On the way out of jQuery, we had to entirely rewrite events handling around now standards CustomEvents. 

Accessibility improvements


Not everything that looks like a button behave like a button. You can now choose to generate links (`<a>`) or `<button>`s to expose actions on your nested items in your forms, for a smoother integration with assistive technologies.

Composable ECMAScript 6 modules


The monolithic UMD module has been split into small ECMAScript 6 modules, so you can import only parts of Cocooned you really want to use. The plugins system has been revamped and now even core functionalities are implemented through it.

Under the hood, we also replaced the deprecated Jasmine JavaScript test runner with Jest, refactored Ruby code to reduce its imprint into `ActionView::Base`, switched from CSS classes to data attributes to hook JavaScript on and prepared the way for more in the future. You can read about the complete list of changes in the gem's changelog.

Even with these heavy changes, Cocooned is still 100% (well, 99%) compatible with the original Cocoon and can be used as a drop-in replacement for an instant upgrade.