Last active
April 28, 2018 12:23
-
-
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.
This file contains 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
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