Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cibernox/ember-cpm
ComputedProperty Macros for Ember
https://github.com/cibernox/ember-cpm
Last synced: 13 days ago
JSON representation
ComputedProperty Macros for Ember
- Host: GitHub
- URL: https://github.com/cibernox/ember-cpm
- Owner: cibernox
- License: mit
- Created: 2013-06-20T02:25:03.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2018-10-28T23:27:54.000Z (about 6 years ago)
- Last Synced: 2024-10-18T07:58:23.808Z (25 days ago)
- Language: JavaScript
- Size: 751 KB
- Stars: 275
- Watchers: 14
- Forks: 31
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Changelog: Changelog.md
- Contributing: CONTRIBUTING.md
- License: LICENSE-APLv2
Awesome Lists containing this project
- awesome-ember - ember-cpm - Computed property Macros for Ember.js. (Packages / Data manipulation & Computed)
README
## Ember-CPM
[![Build Status](https://travis-ci.org/cibernox/ember-cpm.svg?branch=master)](https://travis-ci.org/cibernox/ember-cpm)
[![Ember Observer Score](http://emberobserver.com/badges/ember-cpm.svg)](http://emberobserver.com/addons/ember-cpm)
[![Code Climate](https://codeclimate.com/github/cibernox/ember-cpm/badges/gpa.svg)](https://codeclimate.com/github/cibernox/ember-cpm)
[![Dependency Status](https://david-dm.org/cibernox/ember-cpm.svg)](https://david-dm.org/cibernox/ember-cpm)
[![devDependency Status](https://david-dm.org/cibernox/ember-cpm/dev-status.svg)](https://david-dm.org/cibernox/ember-cpm#info=devDependencies)
![Ember Version](https://embadge.io/v1/badge.svg?start=2.0.0)Computed Property Macros for Ember
### Requirements
Version 2.0+ will only work with Ember 2.0+
Version 3.0+ is only tested in the last 2 LTS.### Installation
Just run `ember install ember-cpm`
### Usage
Just import individual macros from `ember-cpm/macros/*` or all macros from `ember-cpm`.
```js
// Import only one macros
import ifNull from "ember-cpm/macros/if-null";
// or alternatively import all the namespace
import EmberCPM from "ember-cpm";
```### Contributing
To generate a new computed property macros with ember-cli
* Run `ember g macro `. This will generate a few files
* `./addon/macros/dasherized-macro-name.js` (the macro)
* `./addon/tests/dummy/unit/macro/dasherized-macro-name-test.js` (a test)*
* and modify `./addon/ember-cpm.js````javascript
// import the macro
import camelizedMacroName from './macros/dasherized-macro-name.js'
...var Macros = {
...
// allows use via EmberCPM.Macros.camelizedMacroName
camelizedMacroName: camelizedMacroName,
...
};```
`ember d macro ` will do the reverse of these changes### Provided Macros
* `among` -- returns `true` if the original value is among the given literals
(testing using `===`)
* `encodeURIComponent` -- calls `encodeURIComponent` on the original value
* `encodeURI` -- calls `encodeURI` on the original value
* `firstPresent` -- returns the first property with a value, as determined by `Ember.isPresent`
* `fmt` -- pass the original values into a format-string
* `htmlEscape` -- escapes the original value with
`Handlebars.Utils.escapeExpression` *and* wraps the result in a
`Handlebars.SafeString` (since it's now safe)
* `ifNull` -- fall back on a default value
* `promise` -- wraps the original value in an already-resolved promise
* `safeString` -- wraps the original value in a `Handlebars.SafeString`
* `join` -- joins the supplied values together with a provided sepatator
* `quotient` -- divides one numeric property or literal by another
* `difference` -- subtracts one numeric property or literal from another
* `product` -- multiplies numeric properties and literals together
* `sum` -- sums numeric properties and literals together
* `conditional` -- returns values based on a boolean property (good replacement for ternary operator)
* `computedPromise` -- Updates computed property when supplied callback (which must return a promise) is resolved### Composable Computed Property Macros
Unlike Ember's computed property macros, the macros in this addon are *composable*. That means
you define macros inside other macros without defining them in a separate key.```javascript
import Ember from 'ember';
import EmberCPM from 'ember-cpm';const { Macros: { sum, difference, product } } = EmberCPM;
export default Ember.Component.extend({
num1: 45,
num2: 3.5,
num3: 13.4,
num4: -2,total: sum(
sum('num1', 'num2', 'num3'),
difference('num3', 'num2'),
product(difference('num2', 'num1'), 'num4')
)
});
```