Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Externalize babel helpers using @babel/runtime #402

Merged
merged 6 commits into from
Feb 25, 2019

Conversation

petermikitsh
Copy link
Contributor

tl,dr:

This reduces the ES module size from 27545 to 26852 bytes (~2.5%) by externalizing babel runtime helper functions.

Many people are using these helper functions elsewhere. By externalizing them, folks can take advantage of only including a single copy (as opposed to the additional copy that was inlined by react-final-form).

It appears this was the original intent of the repository since @babel/runtime is already a production dependency.

Details

react-final-form.es.js goes from something like this:

import { createElement, Component, createContext } from 'react';
import { fieldSubscriptionItems, configOptions, createForm, formSubscriptionItems, version } from 'final-form';

function _extends() {
  _extends = Object.assign || function (target) {
    for (var i = 1; i < arguments.length; i++) {
      var source = arguments[i];

      for (var key in source) {
        if (Object.prototype.hasOwnProperty.call(source, key)) {
          target[key] = source[key];
        }
      }
    }

    return target;
  };

  return _extends.apply(this, arguments);
}

// Other babel helper functions (not shown).

to this:

import _extends from '@babel/runtime/helpers/extends';
import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/objectWithoutPropertiesLoose';
import _inheritsLoose from '@babel/runtime/helpers/inheritsLoose';
import { createElement, Component, createContext } from 'react';
import { fieldSubscriptionItems, configOptions, createForm, formSubscriptionItems, version } from 'final-form';

//      
function diffSubscription (a, b, keys) {
  if (a) {
    if (b) {
      // $FlowFixMe
      return keys.some(function (key) {
        return a[key] !== b[key];
      });
    } else {
      return true;
    }
  } else {
    return !!b;
  }
}

Related

final-form/react-final-form-arrays#60

@codecov
Copy link

codecov bot commented Dec 21, 2018

Codecov Report

Merging #402 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #402   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          10     10           
  Lines         207    207           
  Branches       61     61           
=====================================
  Hits          207    207

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2f655e7...8cfc0cd. Read the comment docs.

@Andarist
Copy link
Contributor

Yeah, that was the intention implemented in #351 . However seems that I've screwed it up in #366 .

.babelrc.js Outdated
@@ -16,6 +16,7 @@ module.exports = {
],
plugins: [
'@babel/plugin-transform-flow-strip-types',
'@babel/plugin-transform-runtime',
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Andarist Fixed ✅

@Andarist
Copy link
Contributor

@erikras friendly 🏓

@petermikitsh
Copy link
Contributor Author

Fixed merge conflict, all checks pass

@erikras erikras merged commit 1d3ce18 into final-form:master Feb 25, 2019
@erikras
Copy link
Member

erikras commented Mar 4, 2019

Published in v4.1.0

@lock
Copy link

lock bot commented Apr 3, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Apr 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants