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

Throw when component is missing #4

Merged

Conversation

brigand
Copy link
Contributor

@brigand brigand commented Jul 8, 2017

React has a similar warning. Ran into it when working on #3

@vadimdemedes
Copy link
Owner

Shouldn't this be an error, rather than a warning? Otherwise the previous Cannot read property 'prototype' of undefined error is still going to appear after warning.

@brigand
Copy link
Contributor Author

brigand commented Jul 9, 2017

@vadimdemedes fixed.

lib/h.js Outdated
@@ -4,6 +4,10 @@ const flatten = require('lodash.flattendeep');
const VNode = require('./vnode');

module.exports = (component, props, ...children) => {
if (typeof component !== 'function' && typeof component !== 'string') {
throw new TypeError(`ink.h: expected component to be a function, but received "${component}". You may have forgotten to export a component.`);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove ink.h and start with Expected?

Also, replace "${component}" with typeof component.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

test/h.js Outdated
@@ -163,3 +163,10 @@ test.failing('don\'t merge children of components', t => {

t.deepEqual(node.props.children, ['x', 'y']);
});

test('warns on invalid type', t => {
t.throws(() => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=> t.throws(() => h(), 'Expected component to be a function, got undefined. You may have forgotten to export a component.');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

test/h.js Outdated
@@ -163,3 +163,10 @@ test.failing('don\'t merge children of components', t => {

t.deepEqual(node.props.children, ['x', 'y']);
});

test('warns on invalid type', t => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warns => throws
invalid type => missing component

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@vadimdemedes vadimdemedes changed the title h warns on invalid component type Throw when component is missing Jul 9, 2017
@vadimdemedes vadimdemedes merged commit 34ff78e into vadimdemedes:master Jul 9, 2017
@vadimdemedes
Copy link
Owner

Thanks!

@brigand brigand deleted the warn-on-undefined-component branch July 9, 2017 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants