0.2.0 • Published 6 years ago

ember-computed-query v0.2.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

ember-computed-query

Computed properties for your models that's equivalent to your store's query functions

Installation

ember install ember-computed-query

Usage

Querying for multiple records

Options as an object

import Model from 'ember-data/model';
import attr from 'ember-data/attr';

import { query } from 'ember-computed-query';

export default Model.extend({
  username: attr('string'),

  comments: query('comment', {
    filter: {
      author: 'foobar'
    }
  }, 'username')
});

Options as a callback

import Model from 'ember-data/model';
import attr from 'ember-data/attr';

import { query } from 'ember-computed-query';

export default Model.extend({
  username: attr('string'),

  comments: query('comment', (context) => {
    return {
      filter: {
        author: context.get('username')
      }
    };
  }, 'username')
});

Querying for a single record

Options as an object

import Model from 'ember-data/model';
import attr from 'ember-data/attr';

import { queryRecord } from 'ember-computed-query';

export default Model.extend({
  username: attr('string'),

  newestComment: queryRecord('comment', {
    filter: {
      author: 'foobar'
    }
  }, 'username')
});

Options as a callback

import Model from 'ember-data/model';
import attr from 'ember-data/attr';

import { queryRecord } from 'ember-computed-query';

export default Model.extend({
  username: attr('string'),

  newestComment: queryRecord('comment', (context) => {
    return {
      filter: {
        author: context.get('username')
      }
    };
  }, 'username')
});

Notes

  • Because they're computed properties, they're lazily loaded.
  • In the examples above, changing username will invalidate the computed query cache. This means that the computed query will run again on the next access.

Contributing

Installation

  • git clone <repository-url> this repository
  • cd ember-computed-query
  • npm install

Running

Running Tests

  • npm test (Runs ember try:each to test your addon against multiple Ember versions)
  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit https://ember-cli.com/.

0.2.0

6 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.1

7 years ago