# ember-invoke-action

> A slightly more idiomatic way to invoke actions in your Ember components

Latest version **1.5.1** (published 2018-05-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install ember-invoke-action
pnpm add ember-invoke-action
yarn add ember-invoke-action
bun add ember-invoke-action
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.5.1 |
| Published | 2018-05-30 |
| First published | 2015-11-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | ^4.5 \|\| 6.* \|\| >= 7.* |
| Dependencies | 1 |
| Unpacked size | 7.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Marten Schilstra |
| Maintainers | martndemus |
| Keywords | ember-addon |

## Links

- npm: https://www.npmjs.com/package/ember-invoke-action
- Repository: https://github.com/martndemus/ember-invoke-action
- Homepage: https://github.com/martndemus/ember-invoke-action#readme
- Issues: https://github.com/martndemus/ember-invoke-action/issues
- npm.io page: https://npm.io/package/ember-invoke-action

## Dependencies (1)

- [ember-cli-babel](https://npm.io/package/ember-cli-babel.md) ^6.6.0

## Recent versions

- 1.5.1 (latest) — 2018-05-30
- 1.5.0 — 2017-10-25
- 1.4.0 — 2016-08-24
- 1.3.1 — 2016-08-01
- 1.3.0 — 2016-03-02
- 1.2.0 — 2015-11-05
- 1.1.0 — 2015-11-04
- 1.0.0 — 2015-11-04

## README

# ember-invoke-action
[![NPM Version](https://badge.fury.io/js/ember-invoke-action.svg)](http://badge.fury.io/js/ember-invoke-action)
[![Build Status](https://travis-ci.org/martndemus/ember-invoke-action.svg?branch=master)](https://travis-ci.org/martndemus/ember-invoke-action)
[![Ember Observer Score](http://emberobserver.com/badges/ember-invoke-action.svg)](http://emberobserver.com/addons/ember-invoke-action)

A slightly more idiomatic way to invoke actions in your Ember components.

## Installation

```
ember install ember-invoke-action
```

## How To

You can either use `ember-invoke-action` as a helper function or a mixin.

### Mixin usage

```javascript
import Ember from 'ember';
import { InvokeActionMixin } from 'ember-invoke-action';

export default Ember.Component.extend(InvokeActionMixin, {
  click(...args) {
    this.invokeAction('click', ...args);
  }
});
```

### Helper usage

```javascript
import Ember from 'ember';
import { invokeAction } from 'ember-invoke-action';

export default Ember.Component.extend({
  click(...args) {
    invokeAction(this, 'click', ...args);
  }
});
```

### `strictInvokeAction`

As alternative to `invokeAction` you can call `strictInvokeAction`.
`strictInvokeAction` is functionally the same as `invokeAction` except for when
the given action could not be found, then `strictInvokeAction` will raise an
`AssertionError`.

### `invoke`

With the `invoke` helper you can call other actions from the `actions` object as
if it is a closure action.

```javascript
import Ember from 'ember';
import { invoke } from 'ember-invoke-action';

export default Ember.Component.extend({
  actions: {
    saveModel() {
      return get(this, 'model').save();
    },

    closeModal() {
      set(this, 'modalVisible', false);
    },

    saveModelAndClose(...args) {
      invoke(this, 'closeModal');
      return invoke(this, 'saveModel');
    }
  }
});
```

### 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

## Credits

This code was inspired by @miguelcobain, I just made an addon out of it.

License
------------------------------------------------------------------------------

This project is licensed under the [MIT License](LICENSE.md).

---
_Source: https://npm.io/package/ember-invoke-action · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
