feat: React Bloc: BlocProvider & BlocConsumer#29
feat: React Bloc: BlocProvider & BlocConsumer#29prateek14 wants to merge 5 commits intofelangel:masterfrom
Conversation
|
I'll update the test phase |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
| <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.
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.
props.bloc.constructor.name will be minified with any good builder, eg Webpack.
There was a problem hiding this comment.
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.
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.
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.
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.
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.
@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