« first day (500 days earlier)      last day (869 days later) » 

7:28 AM
Bhargav Bhargav Bhargav :)
 
 
8 hours later…
 
2 hours later…
5:14 PM
@TheMaster I think the incantation stopped working once they handed back the diamond :)
@TheMaster oh, that is interesting - the symptoms are definitely similar
 
 
3 hours later…
8:10 PM
@OlegValter That's sad :(
 
8:23 PM
@Bhargav @Bhargav @Bhargav
 
8:36 PM
Can anyone think of any other workaround for lazy loading?
1
A: Avoid Repeating: Use Global Variables in Google Apps Script or Not?

TheMaster You can use the lazy loading technique in my answer To make it dynamic and avoid repetition, You can use enclosing arrow functions(()=>{}) to avoid direct execution and use Object.defineProperty() to add a getter. const g = {};//global object const addGetter_ = (name, value, obj = g) => { Obj...

I tried Classes with Proxy after this, but it's much more bloaty.
 
8:53 PM
@TheMaster yeah, but, well, they served a lot, time to get some rest :)
@TheMaster I normally utilize the memoization pattern
so, for example, something like getting a sheet:
const getSheet = (name) => {
    if(getSheet.sheet) return getSheet.sheet;

    const ss = SpreadsheetApp.getActiveSpreadsheet();
    return (getSheet.sheet = ss.getSheetByName(name));
};
this takes advantage of the fact that all functions are objects first and foremost
I find it quite clean, and the cache is super-easy to clear (either by delete getSheet.sheet or, which is semantically more correct, getSheet.sheet = null;
it is also easily abstractable
I am also extremely baffled to see someone not only use global variables but deliberately use the global binding misfeature that should be considered an error instead
I like your approach of memoizable getters, though, that is pretty much the same thing, come to think of it.
 
9:22 PM
@OlegValter Nice, but for say a dozen of needed variables(with different data returntypes), it gets quite verbose... with the repeated if, return. Then we need to check for if ss is available too in each of those functions right?
 
9:36 PM
@TheMaster of course, that can be abstracted into a caching function if it gets out of hand, just an example
 
9:54 PM
take a look here:
const cache = (callback) => {
   const c = (...args) => {
      return (c.memo = c.memo !== void 0 ? c.memo : callback(...args));
   }
   return c;
}
pure JS version
reusable, clean, no mutations
 

« first day (500 days earlier)      last day (869 days later) »