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

07:28
Bhargav Bhargav Bhargav :)
 
8 hours later…
 
2 hours later…
17:14
@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…
20:10
@OlegValter That's sad :(
20:23
@Bhargav @Bhargav @Bhargav
20:36
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.
20:53
@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.
21:22
@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?
21:36
@TheMaster of course, that can be abstracted into a caching function if it gets out of hand, just an example
21:54
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 (1105 days later) »