unirakun / k-ramel

State manager for your components apps, the safe and easy way
MIT License
21 stars 5 forks source link

redux-form driver build needs regeneratorRuntime #197

Closed bpetetot closed 5 years ago

bpetetot commented 6 years ago

I configured redux-form driver with my project and it seems that the build of @k-ramel/driver-redux-form needs to have regeneratorRuntime as dev dependency to use it in my app.

I get this error when I try to use asyncSubmit methods

regeneratorRuntime is not defined

When I inspect the transpiled / uglyfied lib, I get that @k-ramel/driver-redux-form:

(n = regeneratorRuntime.mark(function e(n) {
          for (var i = arguments.length, c = Array(i > 1 ? i - 1 : 0), s = 1; s < i; s++) { c[s - 1] = arguments[s] }
          let f
          return regeneratorRuntime.wrap(
            (e) => {
              for (;;) {
                switch ((e.prev = e.next)) {
                  case 0:
                    return o(r.startSubmit(t)), (e.next = 3), n(...u(c))
                  case 3:
                    return (
                      (f = e.sent),
                      r.isSubmitting(t)(a()) && o(r.stopSubmit(t)),

So you should use babel-plugin-transform-runtime when the lib is transpiled. See explaination here

guillaumecrespel commented 6 years ago

And if you add this on your project directly ? And add information on README.md of @k-ramel/driver-redux-form ?

fabienjuif commented 6 years ago

One of the problem I can see right now is that if this plugin (babel-plugin-transform-runtime) transpile Map/Symbol/etc, and includes core-js.

If you target a recent browser, you don't need core-js. Your bundle is bloated for ... almost nothing, by core-js.

In other hand, the runtimeGenerator is a pain, and it could be great to transpile it: maybe with an other plugin.

Right now, we use this in our current projects :

    "regenerator-runtime": "^0.12.0"
/* eslint-env browser */
import React from 'react'
import ReactDOM from 'react-dom'
import 'normalize.css'
import 'regenerator-runtime/runtime' // <- here
import 'react-vis/dist/style.css'
import App from './app.wrapped'

ReactDOM.render(React.createElement(App), document.getElementById('root'))

This have a minimal bundle size impact.

fabienjuif commented 6 years ago

And BTW, this is also needed for the @k-ramel/driver-http ;)

bpetetot commented 6 years ago

No problem, I will add "regenerator-runtime": "^0.12.0" to my app. Thx. So you can close this issue and the associated PR #198

fabienjuif commented 6 years ago

Before closing this issue, we should add a line into the README.md