-
-
Notifications
You must be signed in to change notification settings - Fork 22
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: React Bloc: BlocProvider & BlocConsumer #29
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is really cool. looks like test phase is failing in the build because they have not been updated to use the new bloc api
I'll update the test phase |
Codecov Report
@@ Coverage Diff @@
## master #29 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 4 3 -1
Lines 111 84 -27
Branches 9 13 +4
=========================================
- Hits 111 84 -27
Continue to review full report at Codecov.
|
<BlocBuilderInternal bloc={props.bloc} builder={props.builder} condition={props.condition} /> | ||
) | ||
} else if (props.type) { | ||
const context = BlocProvider.context<B>(props.type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also noticed we are passing in the type manually. Can we get the name of the bloc using something like props.bloc.constructor.name
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
props.bloc.constructor.name will be minified with any good builder, eg Webpack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, my first iteration used constructor.name, but it doesnt work in following cases:
- Minification
- Old browsers, <IE9
- Classes defined using Prototypical inheritance es5
The new react library, Recoil also uses a unique key method to track a set of state nodes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to note, there is one more possibility, see this implementation https://github.com/cartant/ts-action/blob/master/packages/ts-action/source/action.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think we should consider trying to implement something that removes the need to pass in the type. I think someone also mentions using metadata in https://stackoverflow.com/questions/13613524/get-an-objects-class-name-at-runtime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could merge the PR now and have this as a separate issue to look into. @felangel what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delayed response! Going to take a closer look at this tomorrow and let y'all know what my thoughts are 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@erickjtorres Even if we were to implement an instance property called "type" as suggested by Lonli or use something like constructor.name, they will be available only in the instance context.
We need to be able to access the key in a static context
const context = BlocProvider.context<B>(props.type)
// No way to access instance properties of B without creating an object first
👋 What's the current status of this PR? |
Hey thanks for bringing this back to my attention! I'll try to take another this this week and hopefully clean up and get something release very soon 👍 |
Hei @felangel did you have a chance to check it? |
This is the only absent feature that is keeping me from using bloc.js in production. Would be great if this was merged. |
I'll try to take a look over the weekend and get this merged, sorry for the delay here! |
news on this? would be a nice alternative to passing the bloc through useContext |
Sorry keep getting side-tracked! Will try to make time today 👍 |
Status
IN DEVELOPMENT
Breaking Changes
NO
Description
APIs for BlocProvider and BlocConsumer using React Context API
Type of Change