-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Components with containers #45
Comments
That's the kind of thing I'm looking at. With React Komposer, I use a way to disable the container functionality at all. I hope we can do a much better job as well. |
Looking for some ideas. |
One option that comes to mind is stub the context. Another idea is providing a parameter to original container: export default composeAll(
'myComponentKey'
composeWithTracker(composer),
useDeps(depsMapper)
)(Component); story file: // will cause composeAll in the original container file to ignore the composers
// provided to it and wrap the dumb component using testComposer
stubComposer('myComponentKey', composeWithTracker(testComposer)); Another option is to have In the previous example, this means importing the "dumb" component in the story file, defining a composer for it: story file: import dumbComponent from '../my_dumb_component.jsx';
stubComposer(dumbComponent, composeWithTracker(testComposer)); original container: // Component is the same as dumbComponent, so the composer will use testComposer instead
export default composeAll(
composeWithTracker(composer),
useDeps(depsMapper)
)(Component); |
I have implemented my last suggestion for react-komposer. It works pretty well, as long as you don't need more than one composer type for the same component type (which seems to me like a reasonable expectation). If I have a component that depends on a composition, I can enable the test mode and register a stub composer for it, which will override the original composer: original component: // components/my_component.js
import React from 'react';
import OtherComponet from '../containers/other_component';
class MyComponent extends React.Component {
render() {
return (<OtherComponet foo="bar" />);
}
}
export default MyComponent; If not stubbed, it may fail to get data, so let's create a stub: // components/.stories/composer.js
import OtherComponet from '../other_component.jsx';
import {
createStubComposers, setTestMode, compose
} from 'react-komposer';
const myStubComposer = (props, onData) => {
// get data here
onData(null, data);
};
setTestMode(true);
createStubComposers(OtherComponet, compose(myStubComposer)); and now we can use // components/.stories/my_component.js
import React from 'react';
import { storiesOf, action } from '@kadira/storybook';
import './composer'; // this is the file that registers the composer stub. import it before MyComponent
import MyComponent from '../my_component.jsx';
storiesOf('core.MyComponent', module)
.add('default view', () => {
return (<MyComponent />);
}); @arunoda , any thoughts? |
@MasterAM overall, this seems like a good idea. |
@arunoda, PR sent. In the stub setup file I import those fixtures and the base component, use the fixtures in the stub composer function and call It is also possible use a completely different composer with the same component later on (if another component is using a composition that includes it) by overriding the stub composer for it. It can by done by calling the It all depends on the identity of the composer at the moment of invoking the function returned from |
you might want to try https://github.com/gavriguy/react-indie which has some similar concepts to react-komposer but takes a different approach for handling data defaults, data loading and errors. it lets the component itself deal with the ui of all of the above making it a perfect fit. it even uses storybook to showcase how the component works. (note: im the creator of react-indie) |
@gavriguy great. And you can publish your storybook to GitHub pages. |
@MasterAM Some of us are following the Mantra spec, which usually has 2 composer types for each component type, so I had to use a different approach. @arunoda It doesn't look like https://github.com/gavriguy/react-indie would work well with mantra-core either. I added a composeAllWithStub function on top of the setTestMode. Will submit PR shortly. |
I run @MasterAM 's setTestMode(), then export default composeAllWithStub([
composeWithTracker(composer),
useDeps(depsMapper)
],[
compose(composerStub),
useDeps(depsMapperStub)
])(Component); Please check mantrajs/mantra-sample-blog-app#110 to see a working example. |
@ihealthdavid I created @arunoda It does not look like PRs for ReactKomposer are getting much love. Any chance to change that? |
@MasterAM I'm taking all of them in this week. Stay in touch. |
Hi all, I've looked at all these options. They are great. I hope that's more than enough. |
Thanks, @arunoda; this looks fairly elegant and useful. I will implement it soon in one of my apps which uses StoryBook and let you know how it went. 😄 |
@MasterAM great. |
Is there a way to deal with containers-in-component without react-komposer? We use Meteors |
Yes. There is a way. Check Kadira Voice in few hours. |
I think we could close this. |
Add ref: storybook-eol/getstorybook#1 |
Guys, sorry for reviving this thread, but I am interested in your opinion. What really works for me for unit testing is to load all all components and containers as part of the module (mantra-style). Therefore module contains: Then, in the component I load the components from the context from the given module. Such as: export conts Component (props, { modules }) => {
const { Markdown } = modules.core.containers;
return <Markdown text="A" />
}
Component.contextTypes = {
modules: React.PropType.object
} Do you see any issues with this approach? It makes unit testing a breeze. |
As requested by @arunoda in philcockfield/storybook-host#1
Check if defaultSize !== undefined
Use the correct event to detect args change
Loving the storybook! Great job, I already added it to several of my packages to showcase their interfaces.
I've bumped into an issue, when a component contains a container that snatches its own data. The data are taken reactively from Meteor source. What is the workflow to accomodat these types of components?
The text was updated successfully, but these errors were encountered: