Hey


I tried looking this up but I couldn’t find anything.


I have to different firebase objects:


1. speechList has:
1.1 $asArray of objects, each of which has:
1.1.1 .title
1.1.2 .createdOn
1.1.3 .key (this is the foreign key to the full speech object)


2. currentSpeech. An $asObject() which has
2.1 .title
2.2 .content
2.3 .createdOn


So speechList has many items in it, one of them has a reference to currentSpeech.


Both objects are shown on the page.


I want to keep currentSpeech.title and speechList[id].title in sync.


Is there a best way to do this?


Here is the current way I’m doing it (which seems bloated)


0. Create a new object called activeSpeechListItem, this will be the object from speechList that has a reference to currentSpeech
1. Create isCurrentSpeechLoaded and set to false
2. Create isSpeechListLoaded and set to false
3. When currentSpeech is loaded (which could happen after 4):
3.1 Set isCurrentSpeechLoaded to true.
3.1 Attempt to set activeSpeechListItem. Will not if isSpeechListLoaded is still false.
4. When speechList is loaded (which may happen before 3):
4.1 Set isSpeechListLoaded to true.
3.1 Attempt to set activeSpeechListItem.Will not if isCurrentSpeechLoaded is still false.


Meanwhile:


0. Everytime currentSpeech.title input field has a change event:
1. If the above process has finished and everything is loaded:
1.1 Update aciteSpeechListItem.title from currentSpeech.title
1.2 $save object
2. Else do nothing.


It seems to work, but it’s clogged up my controller and feels heavy. Ideally, I was hoping there was some type of built in function that could do it all for me :)


The full code is here: https://github.com/MakeAwesomeStuff/makeawesomespeeches/blob/844d42c18c47e71d0fccbe18372006171a299116/app/scripts/controllers/account.js


Cheers


David

--
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/1423637442917.01aaeb4d%40Nodemailer.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Kato Richardson at Feb 11, 2015 at 9:26 pm
    Hi David,

    As a general preference, I like to normalize the data by fetching the
    fields from the indexed records on demand. Here's an example taking this
    approach in AngularFire, to cache a list of user names related to chat
    messages with $extendFactory <http://jsfiddle.net/katowulf/vspo65qm/> and
    another with separate scope objects <http://jsfiddle.net/katowulf/uoe5yt8x/>.
    The first is a bit more elegant and also complex to grok and build, the
    second is simple and effective, but limited in flexibility.

    If that doesn't sound like your cup o tea, there is not currently any
    built-in functionality to "fan out" data as you've described here, although
    some of the current projects our engineers are working on will be extremely
    helpful with this sort of use case.

    Generally, since one of these is the master data (i.e. the currentSpeech in
    this case), perfection here isn't necessary. It's often sufficient to have
    the user write to both, making sure the master updates first, and to handle
    edge cases like losing connection between write events with a simple audit
    report or cleanup script to detect discrepancies and sync copies back to
    master.

    Cheers,
    Kato

    On Tue, Feb 10, 2015 at 11:50 PM, David Langford wrote:

    Hey

    I tried looking this up but I couldn’t find anything.

    I have to different firebase objects:

    1. *speechList* has:
    1.1 $asArray of objects, each of which has:
    1.1.1 *.title*
    1.1.2 *.createdOn*
    1.1.3 *.key* (this is the foreign key to the full speech object)

    2. c*urrentSpeech*. An $asObject() which has
    2.1 *.title*
    2.2 *.content*
    2.3 *.createdOn*

    So speechList has many items in it, one of them has a reference to
    currentSpeech.

    Both objects are shown on the page.

    *I want to keep currentSpeech.title and speechList[id].title in sync*.

    Is there a best way to do this?

    Here is the current way I’m doing it (which seems bloated)

    0. Create a new object called *activeSpeechListItem, *this will be the
    object from *speechList* that has a reference to *currentSpeech*
    1. Create *isCurrentSpeechLoaded* and set to false
    2. Create *isSpeechListLoaded* and set to false
    3. When *currentSpeech* is loaded (which could happen after 4):
    3.1 Set *isCurrentSpeechLoaded* to true.
    3.1 Attempt to set *activeSpeechListItem. *Will not if *isSpeechListLoaded
    *is still false.
    4. When *speechList* is loaded (which may happen before 3):
    4.1 Set *isSpeechListLoaded* to true.
    3.1 Attempt to set *activeSpeechListItem.*Will not if
    *isCurrentSpeechLoaded* is still false.

    Meanwhile:

    0. Everytime *currentSpeech.title* input field has a change event:
    1. If the above process has finished and everything is loaded:
    1.1 Update *aciteSpeechListItem.title *from *currentSpeech.title*
    1.2 $save object
    2. Else do nothing.

    It seems to work, but it’s clogged up my controller and feels heavy.
    Ideally, I was hoping there was some type of built in function that could
    do it all for me :)

    The full code is here:
    https://github.com/MakeAwesomeStuff/makeawesomespeeches/blob/844d42c18c47e71d0fccbe18372006171a299116/app/scripts/controllers/account.js

    Cheers

    David


    --
    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/1423637442917.01aaeb4d%40Nodemailer
    <https://groups.google.com/d/msgid/firebase-angular/1423637442917.01aaeb4d%40Nodemailer?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/CADypTEY2cCqFV_hS0sbxchLzsC9CN-pDAVKR9Wymg%2BxEh%2BfjTQ%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupfirebase-angular @
postedFeb 11, '15 at 6:50a
activeFeb 11, '15 at 9:26p
posts2
users2

2 users in discussion

David Langford: 1 post Kato Richardson: 1 post

People

Translate

site design / logo © 2021 Grokbase