Skip to content

Move injectors code to external library - #2749

Merged
julienben merged 10 commits into
react-boilerplate:devfrom
BenLorantfy:move-injectors-to-library
Oct 27, 2019
Merged

Move injectors code to external library#2749
julienben merged 10 commits into
react-boilerplate:devfrom
BenLorantfy:move-injectors-to-library

Conversation

@BenLorantfy

@BenLorantfy BenLorantfy commented Sep 19, 2019

Copy link
Copy Markdown
Collaborator

This PR moves the injector-related code to a new external library called redux-injectors. For the full discussion on how we got here, see this issue. A few guiding notes:

A few other links:

@julienben

julienben commented Sep 22, 2019

Copy link
Copy Markdown
Member

馃槏馃槏馃槏
image

Quick question: Why do we need to add aliases for react deps in the webpack config?

@BenLorantfy

Copy link
Copy Markdown
Collaborator Author

That was just for local development and is needed when using yarn link to link redux-injectors to react-boilerplate. Planning on removing it once redux-injectors is published and before merging this.

@BenLorantfy
BenLorantfy force-pushed the move-injectors-to-library branch from eceacab to e0cdec1 Compare October 24, 2019 15:03
@BenLorantfy
BenLorantfy marked this pull request as ready for review October 24, 2019 15:05
@BenLorantfy BenLorantfy changed the title [Please do not review yet] Move injectors to library Move injectors to library Oct 24, 2019
@BenLorantfy BenLorantfy changed the title Move injectors to library Move injectors code to external library Oct 24, 2019
@BenLorantfy

Copy link
Copy Markdown
Collaborator Author

OK, this is now ready for review whenever anyone has a chance 馃檪

@BenLorantfy

Copy link
Copy Markdown
Collaborator Author

@julienben When you have some time, I also need help transferring redux-injectors to the reactboilerplate org as I explained in this comment: #2698 (comment)

@julienben

Copy link
Copy Markdown
Member

I think the transfer is done:
image
Will review the code asap. Please notice that CI isn't passing though. I think it's related to coverage having dropped.

@BenLorantfy

Copy link
Copy Markdown
Collaborator Author

Oh, I think it dropped because I removed a lot of code that was well tested, I'll see if I can add some more tests elsewhere.

@julienben

Copy link
Copy Markdown
Member

I haven't taken a deep look at this PR's changes yet but maybe also check if some of the tests you removed were testing code outside the injectors?

@coveralls

coveralls commented Oct 25, 2019

Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 100.0% when pulling 631bcda on BenLorantfy:move-injectors-to-library into 9afffea on react-boilerplate:dev.

@BenLorantfy

Copy link
Copy Markdown
Collaborator Author

I checked and I don't think I removed any tests that were testing other code. I did remove some configureStore tests but the coverage for that file is still 100%.

I fixed the coverage by adding some tests for LanguageProvider and Loadable. Also copied the folder app/containers/LanguageProvider/tests to internals/templates/containers/LanguageProvider/tests because it was missing previously.

@julienben

Copy link
Copy Markdown
Member

Thanks!!

Just one thing: Can you undo the copying of app/containers/LanguageProvider/tests? This is already handled by the cleaning script (lines 17 to 20).

@BenLorantfy

Copy link
Copy Markdown
Collaborator Author

Ah I see, done

@julienben julienben left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hey! Looks awesome overall. Just left a few small comments.

Also:

  • Make sure you merge the latest changes from dev and fix the conflicts. (Sorry, I merged a few PRs over the weekend 馃槄)
  • Did you check if code-splitting/loadable still works the same? I'm just worried that we lost that feature partially since the containers import from redux-injectors and the store setup does too. To test it, compare the webpack output of a build from the dev branch and your branch. They won't be exactly the same but you should see one file for each container. (Use webpack analyze if necessary.)
  • Any comments on files in the app folder also apply to the internals of course.

One more thing you might want to do is run a regression test as described in deployment.md. Just make sure you uncomment the git commit line in clean.js.

Comment thread app/configureStore.js Outdated
}

const sagaMiddleware = createSagaMiddleware(reduxSagaMonitorOptions);
const runSaga = sagaMiddleware.run;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Slightly prettier maybe:

const { run: runSaga } = sagaMiddleware;

Comment thread app/containers/LanguageProvider/tests/selectors.test.js
Comment thread app/tests/store.test.js Outdated
expect(typeof store.runSaga).toBe('function');
});
it('should return a redux store', () => {
const store = configureStore({}, browserHistory);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Here browserHistory is undefined because it's an old obsolete API from react-router. You'll see it's been removed in #2791. You'll get a merge conflict here. You can just remove that argument and the test should pass just fine without it.

Comment thread app/tests/store.test.js Outdated
});
it('should return a redux store', () => {
const store = configureStore({}, browserHistory);
expect(typeof store).toBe('object');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's a bit light to say it should return a redux store but then just check that it's of type object. You should use some of the same checks that used to be in checkStore. And IMO there's nothing wrong with also checking for the presence of the keys which are added by redux-injectors (runSaga, injectedSagas, injectedReducers, and replaceReducer too or is that gone now?).

@BenLorantfy BenLorantfy Oct 27, 2019

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

So I added in a more robust test for checking if it returned a redux store. I'm hesitant to check for injectedSagas, injectedReducers, etc, because I'd consider that an internal implementation detail of redux-injectors. I'd like to be able to change that in the future if we need to without breaking react-boilerplate tests.

Comment thread app/utils/tests/loadable.test.js
Comment thread docs/js/remove.md
1. Remove `expect(() => checkStore({ ...store, injectedSagas: null })).toThrow();`
2. Remove `expect(() => checkStore({ ...store, runSaga: null })).toThrow();`
4. Remove statement `const runSaga = sagaMiddleware.run;`
5. Remove `runSaga` from `createInjectorsEnhancer` params

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this actually work? You can use redux-injectors without redux-saga?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

kind of. It throws some invariant warnings. I could probably disable them in redux-injectors

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could it be done by checking which keys are passed to createInjectorsEnhancer? It can be like a configuration object for the injectors and will be especially useful later if/when you add more integrations to them.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(No emergency here. We can merge this branch without this being present in injectors.)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Possibly, I'd have to look into it more

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No rush. Just consider it for a future release of injectors.

Comment thread docs/js/redux-injectors.md Outdated
# `redux-injectors`

`redux-injectors` is a library we made ourselves by moving code we used to have
in the utils folder into a seperate library. It allows you to dynamically load

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would replace the first sentence with something like this:

redux-injectors is an official react-boilerplate companion library. We built it so that it can be used and maintained independently from react-boilerplate.

It allows you to dynamically load...

It feels slightly more professional IMO.

Comment thread internals/generators/container/index.js.hbs
Comment thread docs/js/redux-injectors.md
@BenLorantfy

BenLorantfy commented Oct 27, 2019

Copy link
Copy Markdown
Collaborator Author

Looks like code-splitting is still working, I can see FeaturePage and HomePage are in two different files in the webpack output:

Screen Shot 2019-10-27 at 1 13 00 PM

Regression test:

Example App:

  • Browse example app on development server
    • Browse Features page, change language to de
    • Browse NotFound page
  • Browse example app on dev tunnel
  • Browse example app on Production server
  • Browse example app offline

Internal Commands:

  • npm run clean (Be careful, this will commit all your changes.)
  • npm run generate component TestComp /w defaults
  • npm run generate container TestPage /w defaults

Comment thread docs/js/redux-saga.md Outdated
Comment thread docs/js/README.md
Comment thread internals/generators/container/index.js.hbs
Comment thread internals/scripts/helpers/get-npm-config.js Outdated
Comment thread internals/templates/tests/i18n.test.js Outdated
Comment thread internals/scripts/npmcheckversion.js Outdated

@julienben julienben left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@BenLorantfy it's been a pleasure working with you on this. Thanks for your patience and your attention to detail! I hope you'll continue contributing!

@BenLorantfy

Copy link
Copy Markdown
Collaborator Author

No problem, thanks for your guidance and help with this 馃憤

@julienben
julienben merged commit 2059424 into react-boilerplate:dev Oct 27, 2019
@lock

lock Bot commented Nov 26, 2019

Copy link
Copy Markdown

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 Nov 26, 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