Skip to content

leepfrog/ember-route-action-helper

 
 

Repository files navigation

ember-route-action-helper Build Status npm version

Credit: @rwjblue's jsbin

Demo: http://jsbin.com/jipani/edit?html,js,output

ember install ember-route-action-helper

The route-action helper allows you to bubble closure actions, which will delegate it to the currently active route hierarchy per the bubbling rules explained under actions. Like closure actions, route-action will also have a return value.

However, returning true in an action will not preserve bubbling semantics. In case you would like that behavior, you should use ordinary string actions instead.

Usage

For example, this route template tells the component to lookup the updateFoo action on the route when its internal clicked property is invoked, and curries the function call with 2 arguments.

{{! foo/route.hbs }}
{{foo-bar clicked=(route-action "updateFoo" "Hello" "world")}}

If the action is not found on the current route, it is bubbled up:

// application/route.js
import Ember from 'ember';

const { Route, set } = Ember;

export default Route.extend({
  actions: {
    updateFoo(...args) {
      // handle action
      return 42;
    }
  }
});

The route-action has a return value:

// foo/component.js
import Ember from 'ember';

const { Component } = Ember;

export default Component.extend({
  actions: {
    anotherAction(...args) {
      let result = this.get('updateFoo')(...args);

      console.log(result); // 42
    }
  }
});

You may also use in conjunction with the {{action}} helper:

<button {{action (route-action 'updateFoo')}}>Update Foo</button>

Compatibility

This addon will work on Ember versions 1.13.x and up only, due to use of the new Helper implementation.

Installation

  • git clone this repository
  • npm install
  • bower install

Running

Running Tests

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

Building

  • ember build

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

Legal

DockYard, Inc © 2015

@dockyard

Licensed under the MIT license

About

Bubble closure actions in routes

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 83.0%
  • HTML 17.0%