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

Add support for logger labels #778

Merged
merged 2 commits into from
Dec 3, 2016
Merged

Add support for logger labels #778

merged 2 commits into from
Dec 3, 2016

Conversation

doug-wade
Copy link
Collaborator

Fixes #738 by adding support for labels

server: 133,
client: 'rgb(127,42,127)'
}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Ooh, this is nicer output even without a label!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah that hack was pretty hacky...

// the code again from the ast) or change the module tagger to take an
// options object, rather than a string.
const arg = node.arguments[0];
options.label = arg.properties[0].value.value;
Copy link
Contributor

Choose a reason for hiding this comment

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

loggerSpec actually expects the label to be passed in, and it incorporates it into the name.

So I think something like this would work:

const label = arg.properties[0].value.value;
const options = JSON.parse(loggerSpec({ filePath, trim, prefix, label }));

Though we might be able to more confidently pull out the value associated with a label key (rather than the value associated with the first key) with something like:

const {label} = arg.properties.reduce((o,p) => (o[p.key.value] = p.value.value, o), {});

Not familiar with babel plugins, so don't know if that's the right structure for the entries in arg.properties.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wish it was that nice; optString also requires the parens from the function invocation; e.g.

const label = arg.properties[0].value.value;
const options = JSON.parse(loggerSpec({ filePath, trim, prefix, optString: `{( label: ${label })` }));

I deferred implementation, though, since I'm unclear what the better change is: should I change the loggerSpec api to take an options object, or should I use babel-generator to turn the ObjectExpression I have in hand from the AST into a string, put some parens around it and pass that to loggerSpec. Both have downsides: the first introduces a risk of regression on all the other module taggers, and introduces a breaking change; but the second introduces a dependency I shouldn't really need (and using a code generator in a code generator feels... dicey).

Copy link
Contributor

Choose a reason for hiding this comment

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

the first introduces a risk of regression on all the other module taggers

We control them all, though, right? So it's just a matter of updating our modules to conform to a new interface? Or am I misunderstanding this option?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hypothetically, someone could be using react-server-module-tagger directly

Copy link
Contributor

Choose a reason for hiding this comment

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

notsureiftrolling

properties.push(t.objectProperty(t.identifier(key), literal));
});
return t.objectExpression(properties);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is awesome. 🤘

Thanks for tackling this @doug-wade!

@gigabo gigabo changed the title Fix 738 Add support for logger labels Dec 2, 2016
@gigabo gigabo added the enhancement New functionality. label Dec 2, 2016
@doug-wade doug-wade merged commit 26cfa02 into redfin:master Dec 3, 2016
@doug-wade doug-wade mentioned this pull request Dec 3, 2016
@drewpc drewpc modified the milestone: 0.6.0 Jan 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants