Skip to content

Commit

Permalink
Auto merge of #1 - DockYard:compose, r=poteto
Browse files Browse the repository at this point in the history
Initial work on compose helper

None
  • Loading branch information
homu committed Feb 18, 2016
2 parents f4396cc + bdd6442 commit 58d93fa
Show file tree
Hide file tree
Showing 15 changed files with 192 additions and 39 deletions.
22 changes: 16 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
---
language: node_js
node_js:
- "0.12"

sudo: false
- "stable"

cache:
directories:
- node_modules

addons:
apt:
sources:
- google-chrome
packages:
- google-chrome-stable

env:
- EMBER_TRY_SCENARIO=default
- EMBER_TRY_SCENARIO=ember-1.13
- EMBER_TRY_SCENARIO=ember-2.0
- EMBER_TRY_SCENARIO=ember-2.1
- EMBER_TRY_SCENARIO=ember-2.2
- EMBER_TRY_SCENARIO=ember-2.3
- EMBER_TRY_SCENARIO=ember-release
- EMBER_TRY_SCENARIO=ember-beta
- EMBER_TRY_SCENARIO=ember-canary
Expand All @@ -21,9 +31,9 @@ matrix:
- env: EMBER_TRY_SCENARIO=ember-canary

before_install:
- export PATH=/usr/local/phantomjs-2.0.0/bin:$PATH
- "npm config set spin false"
- "npm install -g npm@^2"
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- "npm install -g npm@^3"

install:
- npm install -g bower
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016
Copyright (c) 2016 DockYard, Inc

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
# Ember-functional-helpers
# ember-functional-helpers [![Build Status](https://travis-ci.org/DockYard/ember-functional-helpers.svg?branch=master)](https://travis-ci.org/DockYard/ember-functional-helpers) [![npm version](https://badge.fury.io/js/ember-functional-helpers.svg)](https://badge.fury.io/js/ember-functional-helpers)

This README outlines the details of collaborating on this Ember addon.
Functional helpers for Ember.

```no-highlight
ember install ember-functional-helpers
```

## Usage

### Compose
Composes two actions in the form of `(f ∘ g)(x)`. Each action must return a value.

```hbs
<button {{action (compose save createNewItem) "Foo"}}>
Create and save item
</button>
```

## Installation

Expand All @@ -24,3 +39,11 @@ This README outlines the details of collaborating on this Ember addon.
* `ember build`

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

## Legal

[DockYard](http://dockyard.com/ember-consulting), Inc &copy; 2016

[@dockyard](http://twitter.com/dockyard)

[Licensed under the MIT license](http://www.opensource.org/licenses/mit-license.php)
11 changes: 11 additions & 0 deletions addon/helpers/compose.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Ember from 'ember';

const { Helper: { helper } } = Ember;

export function compose([f, g]) {
return function(...args) {
return f(g(...args));
};
}

export default helper(compose);
1 change: 1 addition & 0 deletions addon/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as ComposeHelper } from './helpers/compose';
1 change: 1 addition & 0 deletions app/helpers/compose.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default, compose } from 'ember-functional-helpers/helpers/compose';
83 changes: 60 additions & 23 deletions config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,78 @@ module.exports = {
scenarios: [
{
name: 'default',
bower: {
dependencies: { }
dependencies: { }
},
{
name: 'ember-1.13',
dependencies: {
'ember': '~1.13.0'
},
resolutions: {
'ember': '~1.13.0'
}
},
{
name: 'ember-2.0',
dependencies: {
'ember': '~2.0.0'
},
resolutions: {
'ember': '~2.0.0'
}
},
{
name: 'ember-2.1',
dependencies: {
'ember': '~2.1.0'
},
resolutions: {
'ember': '~2.1.0'
}
},
{
name: 'ember-2.2',
dependencies: {
'ember': '~2.2.0'
},
resolutions: {
'ember': '~2.2.0'
}
},
{
name: 'ember-2.3',
dependencies: {
'ember': '~2.3.0'
},
resolutions: {
'ember': '~2.3.0'
}
},
{
name: 'ember-release',
bower: {
dependencies: {
'ember': 'components/ember#release'
},
resolutions: {
'ember': 'release'
}
dependencies: {
'ember': 'components/ember#release'
},
resolutions: {
'ember': 'release'
}
},
{
name: 'ember-beta',
bower: {
dependencies: {
'ember': 'components/ember#beta'
},
resolutions: {
'ember': 'beta'
}
dependencies: {
'ember': 'components/ember#beta'
},
resolutions: {
'ember': 'beta'
}
},
{
name: 'ember-canary',
bower: {
dependencies: {
'ember': 'components/ember#canary'
},
resolutions: {
'ember': 'canary'
}
dependencies: {
'ember': 'components/ember#canary'
},
resolutions: {
'ember': 'canary'
}
}
]
Expand Down
16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ember-functional-helpers",
"version": "0.0.0",
"description": "The default blueprint for ember-cli addons.",
"description": "Functional helpers for Ember",
"directories": {
"doc": "doc",
"test": "tests"
Expand All @@ -11,11 +11,16 @@
"start": "ember server",
"test": "ember try:testall"
},
"repository": "",
"repository": "https://github.com/DockYard/ember-functional-helpers",
"bugs": "https://github.com/DockYard/ember-functional-helpers/issues",
"homepage": "https://github.com/DockYard/ember-functional-helpers",
"engines": {
"node": ">= 0.10.0"
},
"author": "",
"author": [
"Lauren Tan <[email protected]>",
"Marten Schilstra <[email protected]>"
],
"license": "MIT",
"devDependencies": {
"broccoli-asset-rev": "^2.2.0",
Expand All @@ -30,7 +35,6 @@
"ember-cli-release": "0.2.8",
"ember-cli-sri": "^2.0.0",
"ember-cli-uglify": "^1.2.0",
"ember-data": "^2.3.0",
"ember-disable-prototype-extensions": "^1.1.0",
"ember-disable-proxy-controllers": "^1.0.1",
"ember-export-application-global": "^1.0.4",
Expand All @@ -40,7 +44,9 @@
"loader.js": "^4.0.0"
},
"keywords": [
"ember-addon"
"ember-addon",
"functional helpers",
"compose"
],
"dependencies": {
"ember-cli-babel": "^5.1.5"
Expand Down
3 changes: 1 addition & 2 deletions testem.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
"test_page": "tests/index.html?hidepassed",
"disable_watching": true,
"launch_in_ci": [
"PhantomJS"
"Chrome"
],
"launch_in_dev": [
"PhantomJS",
"Chrome"
]
}
14 changes: 14 additions & 0 deletions tests/acceptance/compose-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('Acceptance | compose');

test('it composes actions', function(assert) {
visit('/compose');

andThen(() => assert.equal(currentURL(), '/compose', 'correct url'));
andThen(() => click('#compose-button'));
andThen(() => {
assert.ok(find('pre:contains("Value: 36")').length, 'it returns the right value');
});
});
17 changes: 17 additions & 0 deletions tests/dummy/app/controllers/compose.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Ember from 'ember';

const { Controller, set } = Ember;

export default Controller.extend({
value: 0,

actions: {
add(x, y) {
return x + y;
},

square(x) {
return set(this, 'value', x * x);
}
}
});
1 change: 1 addition & 0 deletions tests/dummy/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const Router = Ember.Router.extend({
});

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

export default Router;
7 changes: 7 additions & 0 deletions tests/dummy/app/templates/components/add-and-square.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<pre>Value: {{value}}</pre>

<button
id="compose-button"
{{action (compose square add) 2 4}}>
Calculate
</button>
7 changes: 7 additions & 0 deletions tests/dummy/app/templates/compose.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="add-and-square">
{{add-and-square
value=value
add=(action "add")
square=(action "square")
}}
</div>
19 changes: 19 additions & 0 deletions tests/unit/helpers/compose-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { compose } from 'dummy/helpers/compose';
import { module, test } from 'qunit';

module('Unit | Helper | compose');

function add(x, y) {
return x + y;
}

function square(x) {
return x * x;
}

test('it composes two functions', function(assert) {
let composed = compose([square, add]);
let result = composed(2, 4);

assert.equal(result, 36, 'it composes two functions');
});

0 comments on commit 58d93fa

Please sign in to comment.