Home

Awesome

Ember-CPM

Build Status Ember Observer Score Code Climate Dependency Status devDependency Status Ember Version

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.

// 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

// import the macro
import camelizedMacroName from './macros/dasherized-macro-name.js'
...

var Macros = {
  ...
  // allows use via EmberCPM.Macros.camelizedMacroName
  camelizedMacroName: camelizedMacroName,
  ...
};

ember d macro <dasherized-macro-name> will do the reverse of these changes

Provided Macros

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.

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')
  )
});