Created
May 17, 2018 15:37
-
-
Save brownsmith/4b2e85ab4fe3c6bdaa2accfbfad8e743 to your computer and use it in GitHub Desktop.
Closure notes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function bookSlotByCustId(customerId) { | |
const custId = customerId | |
return function bookSlot(slotId) { | |
//psuedo code here: | |
dispatch({ | |
apiCall: api.bookSlot(custId, slotId) | |
}); | |
} | |
} | |
const cId = 5 | |
const bookMySlot = bookSlotByCustId(cId); | |
// bookMySlot is *just* a function | |
// assume "time has passed here" | |
// what i really mean is - we have lost the context of our cId variable | |
const sId = 6 | |
bookMySlot(sId) | |
const InTrolleyCounter = (styleModifier, amountSuffix) => ({ productName, quantity }) => { | |
// do something with all 4 varaiables | |
} | |
function InTrolleyCounter (styleModifier, amountSuffix) { | |
return function({ productName, quantity }) { | |
// do something with all 4 varaiables | |
} | |
} | |
// we have stored 'style' and 'amount' at this point - they are bound to x now. | |
const x = InTrolleyCounter('style', 'amount') | |
// here we pass in the second set of args, which we can change whenever we call x | |
x('name', 1) | |
export default { | |
RoundelTrolleyCounter: InTrolleyCounter('roundel', ''), | |
BannerTrolleyCounter: InTrolleyCounter('', ' in trolley'), | |
AdaptiveBannerTrolleyCounter: InTrolleyCounter('adaptToViewport', ' in trolley'), | |
} | |
... | |
import ITC from 'introlleycounter'; | |
const Roundel = ITC.RoundelTrolleyCounter; | |
Roundel('fred', '1') | |
render() { | |
return (<Roundel productName='fred' quantity='1' />) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment