Skip to content

feat: add useBlocBuilder hook#40

Open
theweiweiway wants to merge 4 commits intofelangel:masterfrom
theweiweiway:master
Open

feat: add useBlocBuilder hook#40
theweiweiway wants to merge 4 commits intofelangel:masterfrom
theweiweiway:master

Conversation

@theweiweiway
Copy link
Copy Markdown

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
Copy Markdown

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

@Lonli-Lokli
Copy link
Copy Markdown

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.

2 participants