Skip to content

Latest commit

 

History

History
73 lines (62 loc) · 4.82 KB

MIGRATE.md

File metadata and controls

73 lines (62 loc) · 4.82 KB

Migration guide

v1.2.0

Version 1.2.0 includes a complete refactor of our JavaScript to modernize our code, and provides better compatibility with third-party frameworks, such as React and Angular. You can read more about the rationale and techniques in [this update][] link needed, but here are the notable changes:

Event delegation

All event handlers are managed with delegated event listeners on the <body> element so any dynamically created elements will no longer need to be re-initialized. For instance, if you're importing the accordion component like so:

// ES5
var Accordion = require('uswds/src/js/components/accordion');

// or, in ES2015
import Accordion from 'uswds/src/js/components/accordion';

And if you then use the Accordion constructor to re-initialize dynamically created elements, then you can safely remove all of your accordion-related code — unless you're also using the Accordion methods, show(), hide(), or hideAll(). These methods will remain available in v1.x for backwards compatibility, but the API will change in v2.0.0.

API changes

For backwards compatibility with v1.x, the following JavaScript submodule APIs have been preserved, but will change in v2.0.0:

ES2015

The Standards JavaScript now relies on several features of ES2015 (AKA ES6), the next version of JavaScript. Many ES2015 features aren't yet supported natively by some browsers, so if you're require()-ing the module or its submodules, you'll need to ensure that your bundling or compiling tool supports converting ES2015 to browser-friendly ES5. If you're using any of the following frameworks or tools, this should require zero additional configuration:

  1. React uses Babel under the hood, so if you're using React, you're good to go.
  2. If you're using webpack version 2, then everything in your bundle will be automatically converted to ES5, because webpack 2 supports ES6 natively.
  3. If you're using webpack version 1, we suggest migrating to version 2. Otherwise, you'll need to use babel-loader and configure it with include: [require.resolve('uswds')]. More generally...
  4. If you're already using Babel to compile your JavaScript, be sure that your bundler also compiles third-party modules (i.e. anything in node_modules).
  5. If you're using Angular 2 or later, you're probably already using TypeScript, in which case...
  6. TypeScript's tsc compiler will automatically convert ES2015 to the target ECMAScript version, which defaults to ES3. (Unless you're targeting IE9 or below, you can safely use --target ES5.)