import Ember from 'ember';
import ajax from 'ic-ajax';

const TO_SHOW = 5;
const { computed } = Ember;

export default Ember.Controller.extend({
    init() {
      this._super(...arguments);

      this.fetchingFeed = true;
      this.loadingMore = false;
      this.hasMore = false;
      this.myCrates = [];
      this.myFollowing = [];
      this.myFeed = [];
    },

    visibleCrates: computed('myCreates', function() {
        return this.get('myCrates').slice(0, TO_SHOW);
    }),

    visibleFollowing: computed('myFollowing', function() {
        return this.get('myFollowing').slice(0, TO_SHOW);
    }),

    hasMoreCrates: computed('myCreates', function() {
        return this.get('myCrates.length') > TO_SHOW;
    }),

    hasMoreFollowing: computed('myFollowing', function() {
        return this.get('myFollowing.length') > TO_SHOW;
    }),

    actions: {
        loadMore() {
            this.set('loadingMore', true);
            var page = (this.get('myFeed').length / 10) + 1;

            ajax('/me/updates?page=' + page).then((data) => {
                this.store.pushMany('crate', data.crates);
                var versions = this.store.pushMany('version', data.versions);
                this.get('myFeed').pushObjects(versions);
                this.set('hasMore', data.meta.more);
            }).finally(() => {
                this.set('loadingMore', false);
            });
        }
    }
});

import Ember from 'ember';
import ajax from 'ic-ajax';

const TO_SHOW = 5;
const { computed } = Ember;

export default Ember.Controller.extend({
    init() {
      this._super(...arguments);

      this.fetchingFeed = true;
      this.loadingMore = false;
      this.hasMore = false;
      this.myCrates = [];
      this.myFollowing = [];
      this.myFeed = [];
    },

    visibleCrates: computed('myCreates', function() {
        return this.get('myCrates').slice(0, TO_SHOW);
    }),

    visibleFollowing: computed('myFollowing', function() {
        return this.get('myFollowing').slice(0, TO_SHOW);
    }),

    hasMoreCrates: computed('myCreates', function() {
        return this.get('myCrates.length') > TO_SHOW;
    }),

    hasMoreFollowing: computed('myFollowing', function() {
        return this.get('myFollowing.length') > TO_SHOW;
    }),

    actions: {
        loadMore() {
            this.set('loadingMore', true);
            var page = (this.get('myFeed').length / 10) + 1;

            ajax('/me/updates?page=' + page).then((data) => {
                data.crates.forEach(crate =>
                    this.store.push(this.store.normalize('crate', crate)));

                var versions = data.versions.map(version =>
                    this.store.push(this.store.normalize('version', version)));

                this.get('myFeed').pushObjects(versions);
                this.set('hasMore', data.meta.more);
            }).finally(() => {
                this.set('loadingMore', false);
            });
        }
    }
});

Replace deprecated store.pushMany() calls