Skip to content

Instantly share code, notes, and snippets.

@NoriSte
Created October 15, 2020 06:35
Show Gist options
  • Save NoriSte/5d9ca4abdbffb7bc194be159898a7314 to your computer and use it in GitHub Desktop.
Save NoriSte/5d9ca4abdbffb7bc194be159898a7314 to your computer and use it in GitHub Desktop.
Re-implementing Recoil APIs / article gists
// @see https://github.com/NoriSte/recoil-apis
// core function, it requires the id
function logId(id: string) {
console.log(id);
}
// create a new function that accesses the id thanks to its closure
function createLogid(id: string) {
// pubklic functions, it doesn't require the id
return function () {
logId(id);
};
}
// you can log the iod only if you know it
logId("1");
// higher-order function creation
const logIdWithoutKnowingIt = createLogid("1");
// you can log the id without knowing it
logIdWithoutKnowingIt();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment