-
Notifications
You must be signed in to change notification settings - Fork 15
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
Pricing single properties #25
Conversation
Pull Request Test Coverage Report for Build 3f7ba09ab456b51ed794d7505587844be1d5c1c7-PR-25
💛 - Coveralls |
980cfdb
to
9f97c8b
Compare
const [billingVatNumber, setBillingVatNumber] = useState(''); | ||
const [shippingCountry, setShippingCountry] = useState(''); | ||
const [shippingPostalCode, setShippingPostalCode] = useState(''); | ||
const [shippingVatNumber, setShippingVatNumber] = useState(''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to track state in a larger blob and have the handlers call into it with a spread of the current state? Unsure if that's a no-no, but this is a lot of individual state methods to keep track of.
const [billingAddress, setbillingAddress] = useState({
country: '',
postalCode: '',
vatNumber: ''
});
// ...
<input
type="text"
value={billingAddress.country}
onChange={e => setBillingAddress({ ...billingAddress, country: e.target.value })}
placeholder="Country"
/>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had considered this, but react's recommendation is to only bundle pieces of state together that update together:
we recommend to split state into multiple state variables based on which values tend to change together.
https://reactjs.org/docs/hooks-faq.html#should-i-use-one-or-many-state-variables
Having said that, my original intention was to abstract as little as possible, but the demo is definitely getting long and verbose and generally needs some love. I'm thinking a separate PR after everything else is merged in to clean up some demo-specific stuff is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 good notes in that doc. I think it can improve readability to merge some state together, while tending to use single state updaters for most situations. I'm mostly concerned with making the demo as readable as possible (without impacting perf unnecessarily).
Agreed that the demo could use some improvement. I'd think that there may be a UI lib we could pull in to at least do away with the CSS.
lib/use-checkout-pricing.js
Outdated
let checkoutPricing = recurly.Pricing.Checkout(); | ||
const { subscriptions = [], ...singleInputs } = input; | ||
|
||
checkoutPricing = addSingleInputs(singleInputs, checkoutPricing); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Thinking singleInputs
could use a better name. rest
does seem appropriate, or perhaps scalarInputs
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally agree, I've been thinking this the entire time as well. I picked this var name like 20 seconds into writing the feature thinking I'd think of something later and go back and update and never did. Definitely needs a better name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.finally(() => setLoading(false)); | ||
.catch(error => { | ||
handleError(error); | ||
setLoading(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for flow simplicity, setLoading
can move into a final then
or done
below these two methods.
addSubscriptions(subscriptions, checkoutPricing)
.then(() => checkoutPricing = checkoutPricing.done(() => setPricing(checkoutPricing)))
.catch(handleError)
.then(() => setLoading(false));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried making this change, but in this case, setLoading(false)
fires before setPricing
is called, causing the demo to flash $0.00
before updating to its resolved value $10.00
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will it respect the promise order if you use checkoutPricing.then
instead of checkoutPricing.done
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tried this, but got the same result -- sets loading
to true
before the promise resolves. We can pair on it tomorrow.
30dceed
to
0e96f7d
Compare
d4eecff
to
c652261
Compare
No description provided.