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

feat: add useBlocBuilder hook #40

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

theweiweiway
Copy link

Status

READY

Breaking Changes

NO

Description

useBlocBuilder hook. This is essentially a straight copy over of the BlocBuilder code but turned into a hook. The only differences between the two are:

  • line 13, I needed a mounted variable for the useEffect so that subscribe is only called once on load
  • line 21, I pass in null instead of this
  • line 21, I pass in state and s instead of previous and current. I found that the rebuild was always one state cycle behind so I made this change
  • line 36, I do not do a if (bloc !== thisBloc.current) check. I found that adding this check breaks the code
  • line 38, I do not update previousState and I do not call setState. Doing so broke the code.

I tested it pretty rigorously with condition, as well as yielding several states during one action - I think it should work well. Please let me know what you think!

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)

@theweiweiway theweiweiway changed the title useBlocBuilder feat: add useBlocBuilder hook Jan 31, 2021
@Lonli-Lokli
Copy link

Does it waiting for ending of discussion here felangel/bloc#2526?

@Lonli-Lokli
Copy link

Seems like it's time to revisit PR, @felangel ?

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