Skip to content
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

Bug/contstructor props #6

Merged
merged 2 commits into from
Dec 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/preact.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ function renderComponent(component, opts) {
setComponentProps(inst, childProps, SYNC_RENDER);
}
else {
inst = componentRecycler.create(childComponent);
inst = componentRecycler.create(childComponent, childProps);
inst._parentComponent = component;
component._component = inst;
if (component.base) deepHook(inst, 'componentWillMount');
Expand Down Expand Up @@ -491,9 +491,8 @@ function buildComponentFromVNode(dom, vnode) {
* @private
*/
function createComponentFromVNode(vnode) {
let component = componentRecycler.create(vnode.nodeName);

let props = getNodeProps(vnode);
let component = componentRecycler.create(vnode.nodeName, props);
setComponentProps(component, props, NO_RENDER);
renderComponent(component, DOM_RENDER);

Expand Down Expand Up @@ -835,7 +834,7 @@ let componentRecycler = {
else componentRecycler.components[name] = [component];
},

create(ctor) {
create(ctor, props) {
let list = componentRecycler.components[ctor.name];
if (list && list.length) {
for (let i=list.length; i--; ) {
Expand All @@ -844,7 +843,7 @@ let componentRecycler = {
}
}
}
return new ctor();
return new ctor(props);
}
};

Expand Down
7 changes: 7 additions & 0 deletions test/browser/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,13 @@ describe('render()', () => {

it('should render components with props', () => {
const PROPS = { foo:'bar', onBaz:()=>{} };
let constructorProps;

class C2 extends Component {
constructor(props) {
super(props);
constructorProps = props;
}
render(props) {
return <div {...props} />;
}
Expand All @@ -184,6 +189,8 @@ describe('render()', () => {

render(<C2 {...PROPS} />, scratch);

expect(constructorProps).to.deep.equal(PROPS);

expect(C2.prototype.render)
.to.have.been.calledOnce
.and.to.have.been.calledWithMatch(PROPS, {})
Expand Down