Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mikkopaderes/ember-computed-query
Computed properties for your models that's equivalent to your store's query functions
https://github.com/mikkopaderes/ember-computed-query
Last synced: 16 days ago
JSON representation
Computed properties for your models that's equivalent to your store's query functions
- Host: GitHub
- URL: https://github.com/mikkopaderes/ember-computed-query
- Owner: mikkopaderes
- License: mit
- Created: 2017-08-20T05:06:50.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-11-20T15:57:11.000Z (almost 7 years ago)
- Last Synced: 2024-09-14T13:38:59.261Z (2 months ago)
- Language: JavaScript
- Homepage:
- Size: 19.5 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# ember-computed-query
Computed properties for your models that's equivalent to your store's query functions
## Installation
```bash
ember install ember-computed-query
```## Usage
### Querying for multiple records
#### Options as an object
```javascript
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
```javascript
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
```javascript
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
```javascript
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 ` this repository
* `cd ember-computed-query`
* `npm install`### Running
* `ember serve`
* Visit your app at [http://localhost:4200](http://localhost:4200).### 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/](https://ember-cli.com/).