ember-composable-helpers icon indicating copy to clipboard operation
ember-composable-helpers copied to clipboard

Update readme with arguments & type needed for each helper

Open poteto opened this issue 9 years ago • 7 comments

E.g.

contains

/**
 * contains(needle, haystack);
 * @param {Array} haystack
 * @param {Primitive || Array} needle
 * @return {Boolean}
 */

Checks if a given value or sub-array is contained within an array.

{{contains selectedItem items}}
{{contains 1234 items}}
{{contains "First" (w "First Second Third") }}
{{contains (w "First Second") (w "First Second Third")}}

poteto avatar Feb 23 '16 15:02 poteto

Yes, but maybe something nicer like MDN does:

Contains

Checks if a given value or sub-array is contained within an array.

Syntax

{{contains neelde haystack}}

Parameters

needle (primitive OR array)

What to look for

haystack (array)

The array to look in

Return value

A boolean wether the array contains the given value or sub-array

Examples

{{contains selectedItem items}}
{{contains 1234 items}}
{{contains "First" (w "First Second Third") }}
{{contains (w "First Second") (w "First Second Third")}}

ghost avatar Feb 23 '16 19:02 ghost

I'd be happy to take this on. I can also add YUIDoc or equivalent if it's helpful.

Something like this?

Action helpers

pipe


Pipes the return values of actions in a sequence of actions. This is useful to compose a pipeline of actions, so each action can do only one thing.

The pipe helper is Promise-aware, meaning that if any action in the pipeline returns a Promise, its return value will be piped into the next action. If the Promise rejects, the rest of the pipeline will be aborted.

The pipe helper can also be used directly as a closure action (using pipe-action) when being passed into a Component, which provides an elegant syntax for composing actions:

Syntax

{{action (pipe action1[ action2 ... actionN]) args}}
{{some-component 
  action1=(pipe-action (action "foo") (action "bar"))
}}

Parameters

action1...actionN

One or more actions to be executed from left to right.

args

Zero or more arguments to be passed to the first action i.e. action1.

Return Value

The return value of the last action in the sequence i.e. actionN.

Examples

{{foo-bar
    addAndSquare=(pipe-action (action "add") (action "square"))
    multiplyAndSquare=(pipe-action (action "multiply") (action "square"))
}}
{{! foo-bar/template.hbs }}
<button {{action addAndSquare 2 4}}>Add and Square</button>
<button {{action multiplyAndSquare 2 4}}>Multiply and Square</button>
<button {{action (pipe addToCart purchase redirectToThankYouPage) item}}>
  1-Click Buy
</button>

With ember-route-action-helper

{{foo-bar
    addAndSquare=(pipe-action (route-action "add") (route-action "square"))
}}

⬆️️ back to top

compute


Calls an action as a template helper.

Syntax

{{compute (action "foo") args}}

Parameters

action

An action defined in the component or controller. Alternatively the action can be defined in the route if using ember-route-action-helper.

args

Zero or more arguments to the given action.

Return Value

The return value of action

Examples

The square of 4 is {{compute (action "square") 4}}

With ember-route-action-helper

The square of 4 is {{compute (route-action "square") 4}}

⬆️ back to top

codyjroberts avatar Jun 11 '16 01:06 codyjroberts

@codyjroberts Sorry for the late reaction, but if you are still willing to do this, then please do!

ghost avatar Aug 23 '16 16:08 ghost

@martndemus No worries, I should probably @mention. I actually forgot about this, but I'll happily put this together. I should be able to find some time in the next week to knock it out.

codyjroberts avatar Aug 23 '16 16:08 codyjroberts

Awesome!

ghost avatar Aug 23 '16 17:08 ghost

@martndemus I'm still interested on working on this, it's just been a surprisingly busy start to the semester. Doing work on this branch: https://github.com/codyjroberts/ember-composable-helpers/tree/update_docs as I find time, so let me know if you want me to add you as a collab in case I'm going too slow!

codyjroberts avatar Sep 09 '16 18:09 codyjroberts

You are definitely not going too slow! Keep up the awesome work :)

ghost avatar Sep 09 '16 18:09 ghost