Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature to export group of functions #46

Open
m1-nann opened this issue Jan 6, 2019 · 4 comments
Open

Feature to export group of functions #46

m1-nann opened this issue Jan 6, 2019 · 4 comments

Comments

@m1-nann
Copy link

m1-nann commented Jan 6, 2019

Could we add feature to support adding function into a newObject and then to functions exports.

Let's say if I want to deploy two function functionA and functionB in group alphabet this way:

firebase deploy --only functions:alphabet

at the moment, I would set it up like this

/// index.dart
void main(){
  /// some functionA functionB
  var o = newObject();
  setProperty(
      o,
      'functionA',
      functions.database
          .ref('entries/{user_id}/functionATrigger')
          .onWrite(functionA));
  setProperty(
      o,
      'functionB',
      functions.database
          .ref('entries/{user_id}/functionBTrigger')
          .onWrite(functionB));
  functions['alphabet'] = o;
}
@pulyaevskiy
Copy link
Owner

I was not aware that it's possible to do this way. Could you point me at the docs in JS SDK where this is mentioned?

I'd be curious to see if this works for HTTPS triggers as well (I'd assume not).

@m1-nann
Copy link
Author

m1-nann commented Jan 6, 2019

Found it (couldn't this morning):
https://firebase.google.com/docs/cli/#deploy_specific_functions

for HTTPS, It does actually, because the actually function name when deployed is converted to 'alphabet-functionA' (with the dash) (assuming that was your concern)

@pulyaevskiy
Copy link
Owner

Ok, thanks. Good to know, it might be something recent they added as I don't remember this details the last time a read this doc.

I'd probably approach it by adding a new FunctionGroup class where users can register their functions and then using it to register the whole group. E.g.:

// This is pseudo code
class FunctionGroup {
  final Object _group = newObject();
  operator []=(String key, dynamic function) {
    setProperty(_group, key, function);
  }
}

// ...

class FirebaseFunctions {
  // ...
  operator []=(String key, dynamic function) {
    if (function is FunctionGroup) {
      setExport(key, function._group);
    } else {
      setExport(key, function);
    }
  }
}

@m1-nann
Copy link
Author

m1-nann commented Jan 7, 2019

that sounds good.
I also suggest to have and FirebaseFunction base class (or , so we can use IsFirebaseFunction instead of dynamic. Even if it's empty, still better for type check.

/// as Base
abstract class FirebaseFunction {}
class DatabaseFunctions extends FirebaseFunction {
  final js.FirebaseFunctions _functions;
  DatabaseFunctions._(this._functions);

  /// Returns reference builder for specified [path] in Realtime Database.
  RefBuilder ref(String path) =>
      new RefBuilder._(_functions.database.ref(path));
}

/// OR as interface
class IsFirebaseFunction {}
class DatabaseFunctions implements IsFirebaseFunction {...}

What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants