Skip to content

Instantly share code, notes, and snippets.

@chrispsn
Last active April 28, 2018 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrispsn/5bdfb86ef4f7030d628624d0d5ddc8b7 to your computer and use it in GitHub Desktop.
Save chrispsn/5bdfb86ef4f7030d628624d0d5ddc8b7 to your computer and use it in GitHub Desktop.
Possible alternate Mesh sheet structure. Minimal boilerplate, with auto-caching (albeit shallow) of calcs, and optimised for diff readability.
const ROOT = [
['hello', [1, 1], $ => `world`],
['calc', [0, 0], $ => $['hello']],
].reduce((o,[k,g,v]) => Object.defineProperty(o, k, {
get: () => {
console.log('Recording', k);
delete o[k];
return o[k]=v(o)
},
configurable:true
}), {})
console.log(ROOT['calc']);
// Won't see 'recording' show up in console for second access
console.log(ROOT['calc']);
// Could use as a template via below (before sheet props are accessed):
// Object.defineProperties(ROOT, {hello: {value: `planet`}});
/* Condenses to:
const ROOT = [
['hello', [1, 1], $ => `world`],
['calc', [0, 0], $ => $['hello']],
].reduce((o,[k,g,v])=>Object.defineProperty(o,k,{get:()=>{
delete o[k];return o[k]=v(o)},configurable:true}),{})
*/
// Could we condense via Object.defineProperties?
// Can we avoid Object.[anything] by getting calc solve order another way?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment