<|start_filename|>tests/dummy/app/components/address-form.js<|end_filename|>
import Component from '@ember/component';
import InboundActions from 'ember-component-inbound-actions/inbound-actions';

export default Component.extend(InboundActions, {
  address: '1 The Blade, Mudpark, Gallinteer, Bublin 16',
  actions: {
    reset: function() {
      this.set('address', '');
    }
  }
});


<|start_filename|>addon/action-proxy.js<|end_filename|>
import EmberObject from '@ember/object';
import Em from 'ember';

export default EmberObject.extend(Em.ActionHandler);


<|start_filename|>tests/dummy/app/components/name-form.js<|end_filename|>
import Component from '@ember/component';
import InboundActions from 'ember-component-inbound-actions/inbound-actions';

export default Component.extend(InboundActions, {
  name: '<NAME>',
  actions: {
    reset: function(...params) {
      this.set('name', '');

      if (params.length) {
        this.set('shouldShowParams', true);
        this.set('params', params.join(', '));
      }
    }
  }
});


<|start_filename|>tests/acceptance/reset-form-test.js<|end_filename|>
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { visit, click } from '@ember/test-helpers';

module('Acceptance tests', function(hooks) {
  setupApplicationTest(hooks);

  test('the component are reset', async function(assert) {
    await visit('/');
    assert.dom('input.name').hasValue('<NAME>');
    assert.dom('textarea.address').hasValue('1 The Blade, Mudpark, Gallinteer, Bublin 16');
    await click('#controller');
    assert.dom('input.name').hasNoValue('The name should have been reset');
    assert.dom('textarea.address').hasNoValue('The address should have been reset');
  });

  test('the send helper sends action with params', async function(assert) {
    await visit('/');
    await click('#send');
    assert.dom('input.name').hasNoValue('The name should have been reset');
    assert.dom('#params').hasText('param1, param2', 'The action is sent params');
  });
});

<|start_filename|>addon/inbound-actions.js<|end_filename|>
import { schedule } from '@ember/runloop';
import { on } from '@ember/object/evented';
import Mixin from '@ember/object/mixin';
import { VERSION } from '@ember/version';
import ActionProxy from './action-proxy';

let scheduleInAfterRender = /^1\.13|^[2-9]/.test(VERSION);

export default Mixin.create({
  _inbound_actions_setup: on('init', function() {
    this._inbound_actions_maybeScheduleInAfterRender(() => {
      var proxy = ActionProxy.create({ target: this });
      this.set('actionReceiver', proxy);
    });
  }),
  _inbound_actions_maybeScheduleInAfterRender: function(fn) {
    if (scheduleInAfterRender) {
      schedule('afterRender', this, fn);
    } else {
      fn();
    }
  },
  onDestroy: on('willDestroyElement', function() {
    this.set('actionReceiver', null);
  })
});
