Angularfire: Unwrapping DataSnapshots

Created on 3 Feb 2016  路  2Comments  路  Source: angular/angularfire

Currently the providers automatically unwrap the DataSnapshots returned from the Firebase database.

Should we provide an option to keep the DataSnapshot intact?

class MyComponent {
  constructor(private af: AngularFire) {
    const obj = af.object('/name', { snapshot: true });
    obj.subscribe((snap) => {
      console.log(snap); 
    });
  }
}

Or perhaps we could use generics

class MyComponent {
  constructor(private af: AngularFire) {
    const obj = af.object<DataSnapshot>('/name');
    obj.subscribe((snap) => {
      console.log(snap); 
    });
  }
}
Firebase(List | Object) feature

Most helpful comment

Hi @davideast & @jeffbcross ,

I am really want to know what kind of scenario we should use preserveSnapshot: true ? I could not find the usage of the 'preserveSnapshot' on the docs

Thank you

All 2 comments

How about unwrapped by default, with an option to preserve the snapshot:

class MyComponent {
  constructor(private af: AngularFire) {
    const obj = af.object('/name', {preserveSnapshot: true});
    obj.subscribe((snap) => {
      console.log(snap); 
    });

    const obj = af.object('/other');
    obj.subscribe((pojs) => {
      console.log(pojs); 
    });
  }
}

Hi @davideast & @jeffbcross ,

I am really want to know what kind of scenario we should use preserveSnapshot: true ? I could not find the usage of the 'preserveSnapshot' on the docs

Thank you

Was this page helpful?
0 / 5 - 0 ratings