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

fix a bug and add a feature #4

Closed
wants to merge 10 commits into from
Closed

Conversation

kessler
Copy link

@kessler kessler commented Sep 18, 2019

  • sometimes the reducer gets called twice because it's an anonymous function, this is fixed by using useCallback hook on the reducer with dependency on initialState:
 const [state, _dispatch] = useReducer((state, action) => reduceState(reducers, state, action), initialState);

=>

const memoizedReducer = useCallback((state, action) => reduceState(reducers, state, action), [initialState])
const [state, _dispatch] = useReducer(memoizedReducer, initialState);
  • Allow the user of the package to provide their own ConnectState implementation

Do you want me to rebase this or something?
Do you need me to provide a code that recreates the bug?

  - publish to personal npm scope
  - remove webpack build and dev deps
  - use index.js in package.json as main
  - relocate src/* to lib/*
  - expose `ConnectState` component so it can be subclassed
  - update docs
by applying a useCallback memoization
@Jahans3
Copy link
Owner

Jahans3 commented Nov 21, 2019

Hey, thanks for this PR. Will take a look over it now - would also be great if you could reproduce the bug too. In the meantime could we keep changes to what is necessary only please

Copy link
Owner

@Jahans3 Jahans3 left a comment

Choose a reason for hiding this comment

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

Thanks again for the PR 👍 left some reviews for you to take a look at

@@ -1,7 +1,6 @@
yarn.lock
yarn-error.log
uss-logo.png
src/
Copy link
Owner

Choose a reason for hiding this comment

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

Why rename this folder?

Copy link
Author

Choose a reason for hiding this comment

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

It's more common to use the lib folder name than src, if it bothers you I can rename that again.

Copy link
Owner

Choose a reason for hiding this comment

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

Yep - necessary changes only please, not personal preference.

@@ -1,3 +1,8 @@
# this is a fork of [Jahans3/use-simple-state](https://github.com/Jahans3/use-simple-state)
Copy link
Owner

Choose a reason for hiding this comment

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

Could we remove before merging please

Copy link
Author

Choose a reason for hiding this comment

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

yup!

class ConnectState extends Component {
state = {};
export class ConnectState extends Component {
constructor(props) {
Copy link
Owner

Choose a reason for hiding this comment

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

Can we remove this constructor please

Copy link
Author

Choose a reason for hiding this comment

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

I'm calling super() in the ctor, so I don't think it can be removed (or will it be called automagically somehow?)

Copy link
Owner

@Jahans3 Jahans3 Nov 25, 2019

Choose a reason for hiding this comment

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

It's just not necessary in this instance. What you've written is functionally identical to state = {}

"peerDependencies": {
"react": "^16.7.0"
},
"devDependencies": {
Copy link
Owner

Choose a reason for hiding this comment

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

Can we get the dev deps back please

Copy link
Author

Choose a reason for hiding this comment

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

Can you elaborate why it's needed? I was trying to reduce dependencies and files in the code

Copy link
Owner

Choose a reason for hiding this comment

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

Because they're necessary to develop the library. Dev dependencies have zero bearing on the final artefact. I would strongly recommend reading up on dev, peer and normal dependencies

@@ -1,37 +0,0 @@
const path = require('path');
Copy link
Owner

Choose a reason for hiding this comment

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

Can we get this back please

Copy link
Author

Choose a reason for hiding this comment

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

Same as above, can you elaborate why it's needed? I was trying to reduce dependencies and files in the code

Copy link
Owner

Choose a reason for hiding this comment

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

A webpack config is required to use webpack and build the project...

@@ -1,2747 +0,0 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
Copy link
Owner

Choose a reason for hiding this comment

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

Can you regenerate this lock file please

Copy link
Author

Choose a reason for hiding this comment

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

lock files are not recommended for libraries, see my comment below about package-lock.json and maybe it applies to yarn as well, I don't actually know much about yarn tbh

Copy link
Owner

Choose a reason for hiding this comment

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

The lockfile is still useful for anyone developing on this project.

@@ -0,0 +1 @@
package-lock=false
Copy link
Owner

Choose a reason for hiding this comment

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

Could we delete this file please - using yarn on this project and prefer to have lock files in place

Copy link
Author

Choose a reason for hiding this comment

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

npm will ignore lock files in dependencies:

One key detail about package-lock.json is that it cannot be published, and it will be ignored if found in any place other than the toplevel package.

from: https://docs.npmjs.com/files/package-lock.json

Copy link
Owner

Choose a reason for hiding this comment

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

This simply disables the lockfile entirely - meaning npm will not generate one. That is not behaviour we want nor do we want to use npm either - this project uses yarn.

@Jahans3
Copy link
Owner

Jahans3 commented Nov 25, 2019

Also need to see a repro of the bug

@kessler
Copy link
Author

kessler commented Dec 2, 2019

I'm going to close this as I don't have the time right now to perform all the changes / create a test case for the bug.
Will reopen when I have a bit more time on my hands...

@kessler kessler closed this Dec 2, 2019
@Jahans3
Copy link
Owner

Jahans3 commented Dec 19, 2019

@kessler No problem. Will try and recreate the bug in the meantime.

Thanks again for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants