Skip to content

"CommonApp" language feature? #183

@hchiam

Description

@hchiam

Expected Behavior

It'd be nice if we could simply do something like CommonApp.getUi().alert(message), with CommonApp having common features shared across different app types.

Actual Behavior

I find I have to create a helper function which returns DocumentApp || SpreadsheetApp || SlidesApp || FormApp, so that I can do things like app().someFunctionIUseALotButInDifferentApps(). For example, app().getUi().alert(message) to show a dialog popup message like in this alert() example:

function alert(message) {
  app().getUi().alert(message);
}

function app() {
  // DocumentApp accesses the current Google Doc.
  // If you use this code in an app type not listed below, you can change this return line to another app type:
  return DocumentApp || SpreadsheetApp || SlidesApp || FormApp; // || SomeOtherAppType
}

Questions

  1. Is there a common class that DocumentApp, SpreadsheetApp, SlidesApp, FormApp, etc. already inherit from that's already in the public API?
  2. If not, could it be exposed for use? Like using a CommonApp object instead of copy-pasting an app() helper function? I understand this might be by design, or might not be a priority use case (in which case I can just continue doing a simple copy-and-paste of the helper function, or just use the non-generic "...App" object specific to the current app type).
  3. Otherwise, maybe an example helper function could be added to the examples folder? If there's interest, I could work on that. I think my example might be missing a few app types. If this is not a priority, no worries.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions