Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tim-evans/ember-service-methods
Shorthand syntactic sugar around Ember Services that are a single method that has no state
https://github.com/tim-evans/ember-service-methods
Last synced: 14 days ago
JSON representation
Shorthand syntactic sugar around Ember Services that are a single method that has no state
- Host: GitHub
- URL: https://github.com/tim-evans/ember-service-methods
- Owner: tim-evans
- License: mit
- Created: 2015-10-06T19:50:38.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2019-01-29T20:45:22.000Z (almost 6 years ago)
- Last Synced: 2024-12-09T10:42:28.297Z (19 days ago)
- Language: JavaScript
- Size: 221 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# ember-service-methods
`ember-service-methods` is an addon that formalizes a pattern that I've used in several larger Ember applications. Some user interactions are inherently complicated and have a lot of business logic around them. These interactions can usually be described in simple terms. For example "Send the invoice to the email given". Using this addon, this interaction could be represented by a service method:
```javascript
import { get } from '@ember/object';
import method from 'ember-service-methods';export default method(function (invoice, { to, subject }) {
return fetch(`/invoices/${get(invoice, 'id')}/email`, {
method: 'POST',
data: {
subject
}
});
});
``````javascript
import Route from '@ember/routing/route';
import { inject as method } from 'ember-service-methods';export default Route.extend({
emailInvoice: method(),actions: {
sendEmail(to, subject) {
return this.emailInvoice(this.modelFor('invoice'), {
to,
subject
});
}
}
});
```This may seem overly complicated to do this simple request. I feel that this pattern works best with testing. Mocking out full API responses to actions can be complicated an error prone. With this pattern along with the built-in test helpers, these methods can be stubbed out for simpler implementations.
This is an implementation of https://github.com/emberjs/rfcs/pull/98
Installation
------------------------------------------------------------------------------* `git clone https://github.com/tim-evans/ember-service-methods.git`
* `cd ember-service-methods`### Linting
* `npm run lint:js`
* `npm run lint:js -- --fix`### Running tests
* `ember test` – Runs the test suite on the current Ember version
* `ember test --server` – Runs the test suite in "watch mode"
* `ember try:each` – Runs the test suite against multiple Ember versions### Running the dummy application
* `ember serve`
* Visit the dummy application at [http://localhost:4200](http://localhost:4200).For more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/).
License
------------------------------------------------------------------------------This project is licensed under the [MIT License](LICENSE.md).