Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move store.filter into an addon #3274

Closed
igorT opened this issue Jun 9, 2015 · 5 comments
Closed

Move store.filter into an addon #3274

igorT opened this issue Jun 9, 2015 · 5 comments

Comments

@igorT
Copy link
Member

igorT commented Jun 9, 2015

We did not come up with solutions for store.filter, and the memory leak problemshould me move store.filter into an addon? And discourage the use? Or just keep in and hope for SemVer compatible fixes in the future
Tomhuda, I trust that you remember what the filter issue is, currently store.filter is kept around forever and leaks all over the place and keeps recomputing

@igorT igorT changed the title Considering moving store.filter into an addon Move store.filter into an addon Jun 11, 2015
@igorT
Copy link
Member Author

igorT commented Jun 11, 2015

cc @fivetanley

@bmac
Copy link
Member

bmac commented Jun 11, 2015

@runspired commented moved form #3298 is copied below:

Considering moving store.filter into an addon

Heartily support of this, it would also show a pattern for extending ember-data features. For instance, I currently crudely add methods to store for lookups based on non-ID keys (unique or just simple K=>V matching) e.g.

/**
     * @method getByKey
     *
     * @param typeName
     * @param key
     * @param value
     * @returns {*} A single or array of records from store if available
     */
    Store.getByKey = function getByKey(typeName, key, value) {

      return Store.filter(typeName, function (record) {
        return record.get(key) === value;
      }).then(function (matches) {
        if (matches.get('length')) {
          return matches;
        }
        return null;
      });
    };


    /**
     * @method getByUniqueKey | return a record based on a unique key
     *
     * @param typeName
     * @param key
     * @param value
     * @returns {*} A single record from store if only one exists for the key, else null
     */
    Store.getByUniqueKey = function getByUniqueKey(typeName, key, value) {

      return Store.filter(typeName, function filterKnownRecords(record) {
        return record.get(key) === value;
      }).then(function (matches) {
        assert("You looked up an item in the store by unique key '" + key + "' that was not a unique value '" + value + "'.", matches.get('length') <= 1);
        if (matches.get('length') === 1) {
          return matches.objectAt(0);
        }
        return null;
      });
    };


    /**
     * @method findByKey
     *
     * @param typeName
     * @param key
     * @param value
     * @returns {*} A single or array of records from store if available, a single or array of records from server if not
     */
    Store.findByKey = function findByKey(typeName, key, value) {

      return Store.filter(typeName, function filterKnownRecords(record) {
        return record.get(key) === value;
      }).then(function (matches) {
        if (matches.get('length')) {
          return matches;
        }
        var query = {};
        query[key] = value;
        return Store.find(typeName, query).then(function (records) {
          return records;
        });
      });
    };


    /**
     * @method findByUniqueKey
     *
     * @param typeName
     * @param key
     * @param value
     * @returns {*} A single or array of records from store if available, a single or array of records from server if not
     *
     * TODO add assertions for uniqueness
     */
    Store.findByUniqueKey = function findByUniqueKey(typeName, key, value) {

      return Store.filter(typeName, function filterKnownRecords(record) {
        return record.get(key) === value;
      }).then(function (matches) {
        assert("You looked up an item in the store by unique key '" + key + "' that was not a unique value '" + value + "'.", matches.get('length') <= 1);
        if (matches.get('length')) {
          return matches.objectAt(0);
        }
        var query = {};
        query[key] = value;
        return Store.find(typeName, query).then(function (records) {
          assert("You looked up an item from the server by unique key '" + key + "' that was not a unique value '" + value + "'.", records.get('length') <= 1);
          if (records.get('length')) {
            return records.objectAt(0);
          }
          return null;
        });
      });
    };

@igorT igorT mentioned this issue Jun 13, 2015
13 tasks
@sarus
Copy link

sarus commented Jun 17, 2015

What's the suggestion for avoiding store.filter use? I know we can pass query params via store.find but then we lose the binding mechanics provided by the RecordArray returned by store.filter.

Thanks!

@sarus
Copy link

sarus commented Jun 17, 2015

Actually just found this: https://github.com/ember-data/ember-data-filter
Was having a problem with ember inspector but now see the full deprecation message. Thanks!

@igorT igorT closed this as completed Jun 24, 2015
@igorT
Copy link
Member Author

igorT commented Jun 24, 2015

It was moved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants