Skip to content

Instantly share code, notes, and snippets.

@michaelfig
Created October 5, 2020 22:11
Show Gist options
  • Save michaelfig/c3b8b9fb1bd3518188db2c951cbde451 to your computer and use it in GitHub Desktop.
Save michaelfig/c3b8b9fb1bd3518188db2c951cbde451 to your computer and use it in GitHub Desktop.
Large table rewrite
const g = 'module-level';
const makeFooOrig = makeStoredInstanceMaker((msg = 'Hello') => {
let invocationCount = 0;
const obj = {
hello(nick) {
console.log(g, obj.getCount());
invocationCount += 1;
return `${msg}, ${nick}!`;
},
getCount() {
return invocationCount;
},
};
return obj;
});
// Fallback:
// const makeStoredInstanceMaker = fn => fn;
const $hmakeFooFromEntry = $hentry => {
// let invocationCount = 0;
const obj = {
hello(nick) {
console.log(g, obj.getCount());
$hentry.invocationCount += 1;
return `${$hentry.msg}, ${nick}!`;
},
getCount() {
return $hentry.invocationCount;
},
};
return obj;
};
const $hfooTable = makeLargeTable('makeFooxxx', $hmakeFooFromEntry);
const makeFoo = (msg = 'Hello') => {
const entry = $hfooTable.createEntry({
msg,
invocationCount: 0,
});
return $hmakeFooFromEntry(entry);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment