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

Plans: add support for client-side currency formatting #6046

Merged
merged 18 commits into from
Jun 17, 2016
Merged
Changes from 1 commit
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
7 changes: 6 additions & 1 deletion client/state/plans/selectors.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External Dependencies
*/
import get from 'lodash/get';

/**
* Internal Dependencies
*/
Expand Down Expand Up @@ -43,7 +48,7 @@ export const getPlan = createSelector(
*/
export function getPlanRawPrice( state, productId, isMonthly = false ) {
const plan = getPlan( state, productId );
if ( ! plan || ! ( plan.raw_price || plan.raw_price === 0 ) ) {
if ( get( plan, 'raw_price', -1 ) < 0 ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

To be honest, this looks rather strange and complicated. I liked your previous solution better. It was more readable. But that's just my opinion and this is a minor detail. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I think an existential operator would read better, but it basically boils down to fetch plan.raw_price if possible, otherwise default to -1.

https://lodash.com/docs#get

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. My point is that a programmer who didn't read the lodash docs or is not super familiar with get won't be able to parse this line quickly. Or to phrase it differently: I did not understand it at first sight, only after going through the lodash docs. :)

return null;
}
return isMonthly ? parseFloat( ( plan.raw_price / 12 ).toFixed( 2 ) ) : plan.raw_price;
Expand Down