-
Notifications
You must be signed in to change notification settings - Fork 7
Description
I really like what you've done with regenerator, I've been playing around with some ideas:
https://github.com/jamiebuilds/renderator
yield <Component/>
By leveraging React.cloneElement() you can eliminate the extra functions being created in each yield:
// before:
let { time } = yield props => <Time {...props}/>;
// after:
let { time } = yield <Time/>;Instead of switching on typeof value === 'function' you can switch on immutagen's context.next function being non-existant. Then modify the props of the context.value with React.cloneElement
if (!context.next) {
return context.value;
} else {
return React.cloneElement(context.value, null, values => {
return compose(context.next(values));
});
}I think it would be good to do this because it requires a lot less typing and is a lot easier to read.
displayName
You can make the returned component look better in React DevTools by providing a displayName which wraps the previous generator's name:
RenderatorComponent.displayName = 'renderator(' + (generator.displayName || generator.name || 'anonymous') + ')';Rename regenerator
Regenerator is already a super similar project which is in wide use. It's actually a requirement to use @astrocoders/regenerator if you want to transform generators functions for the browser today because it's what Babel uses.
I think this project would do better if it had a name that was more accessible. You've got some great words to play with too. The -rator from generator lets you do fun stuff. My first idea was "Renderator"
React RFC
I think I'm going to turn this into an RFC for React to add it directly.
function* Example() {
let { time } = yield <Time/>;
return (
<p>Current time: {time.toLocaleString()}</p>
);
}Someone on the React team (I forget who) already brought up potentially adding a syntax like this.