Hi yet again. I'm trying to figure out how to reuse the same class for my
$extendFactory use. I've tried a couple things but I think I don't
understand Coffeescript classes and Javascript prototype stuff well enough
to understand what I'm doing wrong.

I have "Profiles". A profile object has a bunch of custom methods for
derived fields and custom behavior. I would like to have a single class
that encapsulates these methods & fields, that I can use for
$FirebaseObject, $FirebaseArray, *and* as a non-angularfire object on my
server.

Current approach looks like:

# in a file shared by server and client
# with "di" set to either angular or pongular depending on environment
# extend uses either angular.extend or something else also dep on env
# Model contains some common methods shared by all models in my app
di.module 'Profile', (extend, Model)->
   class Profile extends Model
     constructor: (snap)-> @ref=snap.ref(); @update(snap)
     nameFull: -> @nameFirst + " " + @nameLast
     doSomething: -> # does something with @ref
     update: (snap)-> extend @, snap

# in a file only in the angular client
angular.module 'ProfileArrayFactory', ($FirebaseArray,Invite)->
   $FirebaseArray.$extendFactory(
     $$added: (snap)-> new Invite(snap)
     # and some other stuff, e.g. $$updated
   )

# in a file only in the angular client
# fbProfiles just provides a ref to the data location
anglar.module 'ProfileArray', ($firebase,fbProfiles,ProfileArrayFactory)->
   $firebase(fbProfiles, {arrayFactory:ProfileArrayFactory}).$asArray()

Now, I'm trying to follow a similar process for $FirebaseObject... but I
can't figure out how to reuse the "Profile" class.

# what I think I should be able to do
angular.module 'ProfileObjectFactory', ($FirebaseObject)->
   $FirebaseObject.$extendFactory Profile

angular.module 'ProfileObject',
($firebase,fbProfiles,Profile,ProfileObjectFactory)->
   (key)->

$firebase(fbProfiles.child(key),{objectFactory:ProfileObjectFactory}).$asObject()

But no, this is no good, and the "why" is probably obvious to someone who
understands how angularfire is doing this.

Is what I'm trying to accomplish possible? Any suggestions on how to do
this?

Thanks!

sd

--
You received this message because you are subscribed to the Google Groups "Firebase + AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-angular+unsubscribe@googlegroups.com.
To post to this group, send email to firebase-angular@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-angular/CA%2BwY-3p8M_HjzCaZSzsiF_i-rAspyhszkwG4zHPax_JianfkpQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Kato Richardson at Jan 13, 2015 at 3:53 pm
    Stephen,

    $extendFactory takes a POJO (plain old JavaScript object) containing
    methods to be added onto the prototype. It's not intended to provide
    prototypical inheritance.

    I would just add the methods directly using $extendFactory rather than
    trying to create class hierarchies. As many design books have demonstrated,
    "has a quack" can be much more powerful than "is a duck".

    If you are set on using inheritance, then $extendFactory is not the right
    answer here, and modifying the prototype of an AngularFire array or object
    by any other means isn't something we want to support, as this will lead to
    lots of interesting bugs and conflicts as the API grows in the future. I'd
    recommend instead, that you have your Profile object access the
    synchronized array/object internally rather than trying to include
    AngularFire objects in the inheritance tree.

    Cheers,
    Kato


    On Mon, Jan 12, 2015 at 7:25 PM, Stephen DeBaun wrote:

    Hi yet again. I'm trying to figure out how to reuse the same class for my
    $extendFactory use. I've tried a couple things but I think I don't
    understand Coffeescript classes and Javascript prototype stuff well enough
    to understand what I'm doing wrong.

    I have "Profiles". A profile object has a bunch of custom methods for
    derived fields and custom behavior. I would like to have a single class
    that encapsulates these methods & fields, that I can use for
    $FirebaseObject, $FirebaseArray, *and* as a non-angularfire object on my
    server.

    Current approach looks like:

    # in a file shared by server and client
    # with "di" set to either angular or pongular depending on environment
    # extend uses either angular.extend or something else also dep on env
    # Model contains some common methods shared by all models in my app
    di.module 'Profile', (extend, Model)->
    class Profile extends Model
    constructor: (snap)-> @ref=snap.ref(); @update(snap)
    nameFull: -> @nameFirst + " " + @nameLast
    doSomething: -> # does something with @ref
    update: (snap)-> extend @, snap

    # in a file only in the angular client
    angular.module 'ProfileArrayFactory', ($FirebaseArray,Invite)->
    $FirebaseArray.$extendFactory(
    $$added: (snap)-> new Invite(snap)
    # and some other stuff, e.g. $$updated
    )

    # in a file only in the angular client
    # fbProfiles just provides a ref to the data location
    anglar.module 'ProfileArray', ($firebase,fbProfiles,ProfileArrayFactory)->
    $firebase(fbProfiles, {arrayFactory:ProfileArrayFactory}).$asArray()

    Now, I'm trying to follow a similar process for $FirebaseObject... but I
    can't figure out how to reuse the "Profile" class.

    # what I think I should be able to do
    angular.module 'ProfileObjectFactory', ($FirebaseObject)->
    $FirebaseObject.$extendFactory Profile

    angular.module 'ProfileObject',
    ($firebase,fbProfiles,Profile,ProfileObjectFactory)->
    (key)->

    $firebase(fbProfiles.child(key),{objectFactory:ProfileObjectFactory}).$asObject()

    But no, this is no good, and the "why" is probably obvious to someone who
    understands how angularfire is doing this.

    Is what I'm trying to accomplish possible? Any suggestions on how to do
    this?

    Thanks!

    sd

    --
    You received this message because you are subscribed to the Google Groups
    "Firebase + AngularJS" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to firebase-angular+unsubscribe@googlegroups.com.
    To post to this group, send email to firebase-angular@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/firebase-angular/CA%2BwY-3p8M_HjzCaZSzsiF_i-rAspyhszkwG4zHPax_JianfkpQ%40mail.gmail.com
    <https://groups.google.com/d/msgid/firebase-angular/CA%2BwY-3p8M_HjzCaZSzsiF_i-rAspyhszkwG4zHPax_JianfkpQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
    .
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "Firebase + AngularJS" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to firebase-angular+unsubscribe@googlegroups.com.
    To post to this group, send email to firebase-angular@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-angular/CADypTEavrqQxH%2BVRV2OBzrW7bf7%2BNhUJiYVMXSx6pJn8qzxO6w%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupfirebase-angular @
postedJan 13, '15 at 2:25a
activeJan 13, '15 at 3:53p
posts2
users2

2 users in discussion

Stephen DeBaun: 1 post Kato Richardson: 1 post

People

Translate

site design / logo © 2021 Grokbase