How to use ember-infinity - 8 common examples

To help you get started, we’ve selected a few ember-infinity examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ember-infinity / ember-infinity / tests / dummy / app / routes / demo-scrollable.js View on Github external
import Route from '@ember/routing/route';
import InfinityModel from 'ember-infinity/lib/infinity-model';
import { get } from '@ember/object';
import { inject as service } from '@ember/service';

const ExtendedInfinityModel =  InfinityModel.extend({
  buildParams() {
    let params = this._super(...arguments);
    params['categoryId'] = get(this, 'global').categoryId;
    return params;
  },
  afterInfinityModel(newObjects/*, infinityModel*/) {
    // smoke test.  not really doing anything.  tested at unit level
    return newObjects;
  }
});

export default Route.extend({
  global: service(),
  infinity: service(),

  model() {
github ember-infinity / ember-infinity / addon / mixins / route.js View on Github external
delete options.startingPage;
    delete options.perPage;
    delete options.perPageParam;
    delete options.pageParam;
    delete options.totalPagesParam;
    delete options.countParam;
    delete options.infinityCache;
    delete options.store;
    delete options.storeFindMethod;

    let InfinityModelFactory;
    let didPassBoundParams = !isEmpty(boundParams);
    if (didPassBoundParams) {
      // if pass boundParamsOrInfinityModel, send to backwards compatible mixin that sets bound params on route
      // and subsequently looked up when user wants to load next page
      InfinityModelFactory = InfinityModel.extend(BoundParamsMixin);
    } else if (ExtendedInfinityModel) {
      // if custom InfinityModel, then use as base for creating an instance
      InfinityModelFactory = ExtendedInfinityModel;
    } else {
      InfinityModelFactory = InfinityModel;
    }

    let initParams = {
      currentPage,
      firstPage,
      perPage,
      perPageParam,
      pageParam,
      totalPagesParam,
      countParam,
      _infinityModelName: modelName,
github ember-infinity / ember-infinity / addon / services / infinity.js View on Github external
if (cachedModel) {
        // 2. If cachedModel, get future_timestamp (ms since 1970) and compare to now
        let future_timestamp = Object.keys(cachedModel)[0];
        if (future_timestamp > Date.now()) {
          return cachedModel[future_timestamp];
        } else {
          // 3. cache collection based on new timestamp
          cacheInfinityCollection(_cachedCollection, infinityModel, uniqueIdentifier, infinityCache);
        }
      } else {
        // 2. if we are expired (future_timestamp < Date.now()) or cachedModel doesn't exist, cache a new infinityModel + future timestamp
        cacheInfinityCollection(_cachedCollection, infinityModel, uniqueIdentifier, infinityCache);
      }
    }

    return InfinityPromiseArray.create({ promise: this['loadNextPage'](infinityModel) });
  }
github ember-infinity / ember-infinity / addon / services / infinity.js View on Github external
const currentPage = options.startingPage === undefined ? 0 : options.startingPage - 1;
    // sets first page when route is loaded
    const firstPage = currentPage === 0 ? 1 : currentPage + 1;
    // chunk requests by indicated perPage param
    const perPage = options.perPage || 25;

    // store service methods (defaults to ember-data if nothing passed)
    const store = options.store || get(this, 'store');
    const storeFindMethod = options.storeFindMethod || 'query';

    let infinityModel;
    if (ExtendedInfinityModel) {
      // if custom InfinityModel, then use as base for creating an instance
      infinityModel = ExtendedInfinityModel.create();
    } else {
      infinityModel = InfinityModel.create();
    }

    // check if user passed in param w/ infinityModel, else default
    const perPageParam = paramsCheck('perPageParam', options, infinityModel);
    const pageParam = paramsCheck('pageParam', options, infinityModel);
    const totalPagesParam = paramsCheck('totalPagesParam', options, infinityModel);
    const countParam = paramsCheck('countParam', options, infinityModel);
    const infinityCache = paramsCheck('infinityCache', options, infinityModel);

    // create identifier for use in storing unique cached infinity model
    let identifier = stringifyObjectValues(options);

    delete options.startingPage;
    delete options.perPage;
    delete options.perPageParam;
    delete options.pageParam;
github ember-infinity / ember-infinity / tests / dummy / app / routes / test-scrollable.js View on Github external
import Route from '@ember/routing/route';
import InfinityModel from 'ember-infinity/lib/infinity-model';
import { get, set } from '@ember/object';
import { inject as service } from '@ember/service';

const ExtendedInfinityModel =  InfinityModel.extend({
  global: service(),
  infinityModelUpdated() {
    set(get(this, 'global'), 'isUpdated', true);
  }
});

export default Route.extend({
  infinity: service(),

  model({ page, perPage }) {
    return get(this, 'infinity').model(
      'post',
      { startingPage: page, perPage },
      ExtendedInfinityModel
    );
  }
github 7cart / 7cart / front / app / routes / category.js View on Github external
import Route from '@ember/routing/route';

import {inject as service} from '@ember/service';
import {observer} from '@ember/object';
import {on} from '@ember/object/evented';
import { get } from '@ember/object';
import InfinityModel from 'ember-infinity/lib/infinity-model';

const ExtendedInfinityModel = InfinityModel.extend({
  filter: service(),
  buildParams() {
    let params = this._super(...arguments);
    if (this.get('firstLoad')){
      params['event'] = 'load_more';
    }
    return params;
  },
  afterInfinityModel(nodes) {

    if (nodes.get('meta.attributes.data')) {
      let attrIds = [];

      nodes.get('meta.attributes.data').forEach((item) => {
        if (item.id){
          attrIds.push(item.id);
github ember-infinity / ember-infinity / addon / mixins / route.js View on Github external
if (didPassBoundParams) {
      initParams._deprecatedBoundParams = boundParams;
      initParams.route = this;
    }
    if (infinityModelLoaded) {
      initParams.infinityModelLoaded = infinityModelLoaded;
    }
    if (afterInfinityModel) {
      initParams.afterInfinityModel = afterInfinityModel;
    }

    const infinityModel = InfinityModelFactory.create(initParams);
    get(this, 'infinity._ensureCompatibility')(get(infinityModel, 'store'), get(infinityModel, 'storeFindMethod'));
    get(this, 'infinity.infinityModels').pushObject(infinityModel);

    return InfinityPromiseArray.create({ promise: service['loadNextPage'](infinityModel) });
  },

ember-infinity

Simple, flexible infinite scroll for Ember CLI Apps.

MIT
Latest version published 2 months ago

Package Health Score

78 / 100
Full package analysis