Skip to content

Commit

Permalink
First implementation of helper
Browse files Browse the repository at this point in the history
  • Loading branch information
poteto committed Dec 4, 2015
1 parent 76e142a commit d15d1a8
Show file tree
Hide file tree
Showing 14 changed files with 114 additions and 15 deletions.
8 changes: 5 additions & 3 deletions .travis.yml
@@ -1,16 +1,18 @@
---
language: node_js
node_js:
- "0.12"
- "4.1.2"

sudo: false
sudo: required
dist: trusty

cache:
directories:
- node_modules

env:
- EMBER_TRY_SCENARIO=default
- EMBER_TRY_SCENARIO=ember-1.13
- EMBER_TRY_SCENARIO=ember-release
- EMBER_TRY_SCENARIO=ember-beta
- EMBER_TRY_SCENARIO=ember-canary
Expand All @@ -23,7 +25,7 @@ matrix:
before_install:
- export PATH=/usr/local/phantomjs-2.0.0/bin:$PATH
- "npm config set spin false"
- "npm install -g npm@^2"
- "npm install -g npm@^3"

install:
- npm install -g bower
Expand Down
33 changes: 31 additions & 2 deletions README.md
@@ -1,6 +1,35 @@
# Ember-route-action-helper
# ember-route-action-helper [![Build Status](https://travis-ci.org/dockyard/ember-route-action-helper.svg?branch=master)](https://travis-ci.org/dockyard/ember-route-action-helper) [![npm version](https://badge.fury.io/js/ember-route-action-helper.svg)](https://badge.fury.io/js/ember-route-action-helper)
*Credit: @rwjblue's [jsbin](http://jsbin.com/jipani/edit?html,js,output)*

This README outlines the details of collaborating on this Ember addon.
Demo: http://jsbin.com/jipani/edit?html,js,output

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`. To use:

```hbs
{{! 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:

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

const { Route, set } = Ember;

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

## Compatibility

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

## Installation

Expand Down
26 changes: 26 additions & 0 deletions addon/helpers/route-action.js
@@ -0,0 +1,26 @@
import Ember from 'ember';
import getOwner from 'ember-getowner-polyfill';

const {
Helper,
assert,
computed,
get
} = Ember;

export default Helper.extend({
router: computed(function() {
return getOwner(this).lookup('router:main');
}).readOnly(),

compute([actionName, ...params]) {
let router = get(this, 'router');
assert('[ember-route-action-helper] Unable to lookup router', router);

return function(...invocationArgs) {
let args = params.concat(invocationArgs);

router.send(actionName, ...args);
};
}
});
1 change: 1 addition & 0 deletions app/helpers/route-action.js
@@ -0,0 +1 @@
export { default } from 'ember-route-action-helper/helpers/route-action';
3 changes: 1 addition & 2 deletions bower.json
Expand Up @@ -4,7 +4,6 @@
"ember": "1.13.11",
"ember-cli-shims": "0.0.6",
"ember-cli-test-loader": "0.2.1",
"ember-data": "1.13.15",
"ember-load-initializers": "0.1.7",
"ember-qunit": "0.4.16",
"ember-qunit-notifications": "0.1.0",
Expand All @@ -13,4 +12,4 @@
"loader.js": "ember-cli/loader.js#3.4.0",
"qunit": "~1.20.0"
}
}
}
9 changes: 9 additions & 0 deletions config/ember-try.js
Expand Up @@ -5,6 +5,15 @@ module.exports = {
name: 'default',
dependencies: { }
},
{
name: 'ember-1.13',
dependencies: {
'ember': '~1.13.0'
},
resolutions: {
'ember': '~1.13.0'
}
},
{
name: 'ember-release',
dependencies: {
Expand Down
19 changes: 12 additions & 7 deletions package.json
@@ -1,7 +1,7 @@
{
"name": "ember-route-action-helper",
"version": "0.0.0",
"description": "The default blueprint for ember-cli addons.",
"description": "Bubble closure actions in routes",
"directories": {
"doc": "doc",
"test": "tests"
Expand All @@ -11,11 +11,14 @@
"start": "ember server",
"test": "ember try:testall"
},
"repository": "",
"repository": "https://github.com/dockyard/ember-route-action-helper",
"engines": {
"node": ">= 0.10.0"
},
"author": "",
"author": [
"Robert Jackson <me@rwjblue.com>",
"Lauren Tan <arr@sugarpirate.com>"
],
"license": "MIT",
"devDependencies": {
"broccoli-asset-rev": "^2.2.0",
Expand All @@ -31,19 +34,21 @@
"ember-cli-release": "0.2.8",
"ember-cli-sri": "^1.2.0",
"ember-cli-uglify": "^1.2.0",
"ember-data": "1.13.15",
"ember-disable-proxy-controllers": "^1.0.1",
"ember-export-application-global": "^1.0.4",
"ember-disable-prototype-extensions": "^1.0.0",
"ember-try": "~0.0.8"
},
"keywords": [
"ember-addon"
"ember-addon",
"helper",
"route action"
],
"dependencies": {
"ember-cli-babel": "^5.1.5"
"ember-cli-babel": "^5.1.5",
"ember-getowner-polyfill": "^1.0.0"
},
"ember-addon": {
"configPath": "tests/dummy/config"
}
}
}
12 changes: 12 additions & 0 deletions tests/acceptance/main-test.js
@@ -0,0 +1,12 @@
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('Acceptance | main');

test('it sends a route action', function(assert) {
visit('/thing');

andThen(() => assert.equal(currentURL(), '/thing'));
andThen(() => click('#foo-button'));
andThen(() => assert.equal(findWithAssert('#foo-value').text().trim(), 'Hello world Bob!'));
});
1 change: 1 addition & 0 deletions tests/dummy/app/router.js
Expand Up @@ -6,6 +6,7 @@ const Router = Ember.Router.extend({
});

Router.map(function() {
this.route('thing');
});

export default Router;
11 changes: 11 additions & 0 deletions tests/dummy/app/routes/application.js
@@ -0,0 +1,11 @@
import Ember from 'ember';

const { Route, set } = Ember;

export default Route.extend({
actions: {
updateFoo(...args) {
return set(this, 'controller.foo', args.join(' '));
}
}
});
2 changes: 1 addition & 1 deletion tests/dummy/app/templates/application.hbs
@@ -1,3 +1,3 @@
<h2 id="title">Welcome to Ember</h2>
<h2 id="foo-value">{{foo}}</h2>

{{outlet}}
1 change: 1 addition & 0 deletions tests/dummy/app/templates/components/foo-bar.hbs
@@ -0,0 +1 @@
<button id="foo-button" {{action this.attrs.clicked "Bob!"}}>Click Me!</button>
3 changes: 3 additions & 0 deletions tests/dummy/app/templates/thing.hbs
@@ -0,0 +1,3 @@
<div class="thing-route">
{{foo-bar clicked=(route-action "updateFoo" "Hello" "world")}}
</div>
Empty file removed tests/unit/.gitkeep
Empty file.

0 comments on commit d15d1a8

Please sign in to comment.