如何使用firebase-element获得最大性能数据?

时间:2015-05-22 11:56:02

标签: firebase-polymer

使用firebase-element时,什么被认为是最有效的方法?

  1. 每个位置的新firebase-element。

  2. 使用for循环。

  3. 每个位置的新firebase-element

    ...
    <firebase-element location="https://YOUR-FIREBASE.firebaseio.com/users"></firebase-element>
    <firebase-element location="https://YOUR-FIREBASE.firebaseio.com/products"></firebase-element>
    <firebase-element location="https://YOUR-FIREBASE.firebaseio.com/info"></firebase-element>
    ...
    

    使用for循环。

    ...
    <firebase-login location="https://YOUR-FIREBASE.firebaseio.com/" user="{{fbUser}}"></firebase-login>
    <firebase-element location="https://YOUR-FIREBASE.firebaseio.com/" data="{{fbData}}" dataReady="{{dataReady}}"></firebase-element>
    ...
    Polymer({
        data: null,
        user: null,
    
        observe: {
            'fbData': 'syncData',
            'fbUser dataReady': 'syncUser'
        },
    
        syncData: function() {
            if(this.data.products !== this.fbData.products) {
                this.products = this.fbData.products;
            }
        },
    
        syncUser: function() {
            if(this.fbUser && this.dataReady) {
                for(var user in this.fbData.users) {
                    if(this.fbData.users[user] === this.fbUser.uid) {
                        this.user = this.fbData.users[user];
                    } else {
                        this.user = null;  
                    }               
                }
            }            
        }
    });
    

0 个答案:

没有答案