Skip to content

Feature Request: Add set method to FirebaseListObservable #910

@somombo

Description

@somombo

I have an idea that, in addition to push, update, remove etc ... perhaps, for completeness, we should include destructive set method in FirebaseListObservable, implemented consistently like so:

  set(item?: FirebaseOperation, value?: Object): firebase.Promise<void> {
    if (!value){
      throw new Error("The set method requires a defined non-null value. Use remove method to delete instead.");
    }
    // if no item parameter is provided, destructively replace the whole list with value
    if (!item) {
      return this.$ref.ref.set(value);
    }
    return this._checkOperationCases(item, {
      stringCase: () => this.$ref.ref.child(<string>item).set(value),
      firebaseCase: () => (<firebase.database.Reference>item).set(value),
      snapshotCase: () => (<firebase.database.DataSnapshot>item).ref.set(value),
      unwrappedSnapshotCase: () => this.$ref.ref.child((<AFUnwrappedDataSnapshot>item).$key).set(value)
    });
  }

What do y'all think?
I could PR if fair game

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions