ember install ember-awesome-macros
import nameOfMacro from 'ember-awesome-macros/name-of-macro';
// or
import { nameOfMacro } from 'ember-awesome-macros';
alias for sum
same as Ember.computed.and
, but allows composing
source1: false,
source2: true,
source3: false,
value1: and('source1', 'source2', 'source3'), // false
value2: and(not('source1'), 'source2', not('source3')) // true
alias for collect
wraps Ember.String.camelize
, allows composing
originalValue: 'test-string',
newValue: camelize('originalValue') // 'testString'
wraps Ember.String.capitalize
, allows composing
originalValue: 'test string',
newValue: capitalize('originalValue') // 'Test string'
wraps Ember.String.classify
, allows composing
originalValue: 'test string',
newValue: classify('originalValue') // 'TestString'
same as Ember.computed.collect
, but allows composing
source1: 'my value 1',
source2: 'my value 2',
value: collect('source1', collect('source2')), // ['my value 1', ['my value 2']]
alias for includes
wraps Ember.String.dasherize
, allows composing
originalValue: 'TestString',
newValue: dasherize('originalValue') // 'test-string'
wraps Ember.String.decamelize
, allows composing
originalValue: 'TestString',
newValue: decamelize('originalValue') // 'test_string'
true if source is undefined
source1: undefined,
source2: false,
source3: 'my value',
value1: defaultTrue('source1') // true
value2: defaultTrue('source2') // false
value3: defaultTrue('source3') // 'my value'
subtracts numbers
source1: 3,
source2: 2,
source3: 1,
value1: difference('source1', 'source2', 'source3') // 0
value2: difference('source2', difference('source2', 'source3')) // 2
alias for quotient
like Ember.computed.equal
, but uses dependent properties on both sides
and allows composing
source1: 'my value',
source2: 'my other value',
source3: 'my value',
value1: equal('source1', 'source2') // false
value2: equal('source1', 'source3') // true
alias for peekQueue
get a variable property name from an object
key: 'modelProperty',
model: {
modelProperty: 'my value'
},
value: getBy('model', 'key') // 'my value'
like Ember.computed.gt
, but uses dependent properties on both sides
and allows composing
source1: 1,
source2: 2,
source3: 1,
value1: gt('source1', 'source2') // false
value2: gt('source1', 'source3') // false
value3: gt('source2', 'source3') // true
like Ember.computed.gte
, but uses dependent properties on both sides
and allows composing
source1: 1,
source2: 2,
source3: 1,
value1: gte('source1', 'source2') // false
value2: gte('source1', 'source3') // true
value3: gte('source2', 'source3') // true
build a hash out of computed properties, allows composing
source1: 'my value 1',
source2: 'my value 2',
value: hash({
prop1: 'source1',
prop2: hash({
prop: 'source2'
})
}), // { prop1: 'my value 1', prop2: { prop: 'my value 2' } }
wraps Ember.String.htmlSafe
, allows composing
originalValue: '<input>',
newValue: htmlSafe('originalValue') // will not be escaped
implements Array.prototype.includes()
, allows composing
array: Ember.A(['my value 1', 'my value 2']),
source1: 'my value 2',
source2: 'my value 3',
value1: includes('array', 'source1') // true
value2: includes('array', 'source2') // false
value3: includes(collect(raw('my value 1'), raw('my value 2')), raw('my value 1')) // true
implements Array.prototype.indexOf()
, allows composing
array: Ember.A(['my value 1', 'my value 2']),
source1: 'my value 2',
source2: 'my value 3',
value1: indexOf('array', 'source1') // 0
value2: indexOf('array', 'source2') // -1
value3: indexOf(collect(raw('my value 1'), raw('my value 2')), raw('my value 1')) // 0
wraps Ember.String.isHTMLSafe
, allows composing
source1: '<input>',
source2: htmlSafe('<input>'),
value1: isHtmlSafe('source1'), // false
value2: isHtmlSafe('source2') // true
implements Array.prototype.join()
, allows composing
array: Ember.A(['1', '2']),
separator: ', ',
value1: join('values', 'separator') // '1, 2'
value2: join(collect(raw('1'), raw('2')), raw(', ')) // '1, 2'
alias for peekStack
like Ember.computed.lt
, but uses dependent properties on both sides
and allows composing
source1: 1,
source2: 2,
source3: 1,
value1: lt('source1', 'source2') // true
value2: lt('source1', 'source3') // false
value3: lt('source2', 'source3') // false
like Ember.computed.lte
, but uses dependent properties on both sides
and allows composing
source1: 1,
source2: 2,
source3: 1,
value1: lte('source1', 'source2') // true
value2: lte('source1', 'source3') // true
value3: lte('source2', 'source3') // false
alias for product
same as Ember.computed.not
, but allows composing
source1: true,
source2: false,
value1: not('source1'), // false
value2: not(and('source1', 'source2')) // true
implements http://emberjs.com/api/classes/Ember.MutableArray.html#method_objectAt
, allows composing
array: Ember.A(['my value']),
source1: 0,
source2: 1,
value1: objectAt('array', 'source1') // 'my value'
value2: objectAt('array', 'source2') // undefined
value3: objectAt(collect(raw('my value 1')), raw(0)) // 'my value'
same as Ember.computed.or
, but allows composing
source1: true,
source2: false,
source3: true,
value1: or('source1', 'source2', 'source3'), // true
value2: or(not('source1'), 'source2', not('source3')) // false
get the first item of an array
values: Ember.A(['1', '2']),
firstValue: peekQueue('values') // '1'
get the last item of an array
values: Ember.A(['1', '2']),
firstValue: peekStack('values') // '2'
multiplies numbers
source1: 1,
source2: 2,
source3: 3,
value1: product('source1', 'source2', 'source3') // 6
value2: product('source2', product('source2', 'source3')) // 6
combines promises using RSVP.all
promise1: computed(function() {
return RSVP.resolve('value1');
}),
promise2: computed(function() {
return RSVP.resolve('value2');
}),
promise: promiseAll('promise1', 'promise2') // resolves to ['value1', 'value2']
wraps a promise in the equivalent of DS.PromiseArray
(ArrayProxy
and PromiseProxyMixin
)
products: promiseArray(function() {
return this.store.findAll('product');
})
can also wrap an existing property
productsPromise: computed(function() {
return this.store.findAll('product');
}),
products: promiseArray('productsPromise')
combines promises using RSVP.hash
promise1: computed(function() {
return RSVP.resolve('value1');
}),
promise2: computed(function() {
return RSVP.resolve('value2');
}),
promise: promiseHash('promise1', 'promise2') // resolves to { promise1: 'value1', promise2: 'value2' }
wraps a promise in the equivalent of DS.PromiseObject
(ObjectProxy
and PromiseProxyMixin
)
product: promiseObject(function() {
return this.store.findRecord('product', 1);
})
can also wrap an existing property
productPromise: computed(function() {
return this.store.findRecord('product', 1);
}),
product: promiseObject('productPromise')
subtracts numbers
source1: 3,
source2: 2,
source3: 1,
value1: quotient('source1', 'source2', 'source3') // 1.5
value2: quotient('source2', quotient('source2', 'source3')) // 1.5
a helper if you want to use "literals" in your macros
value1: equal('key1', raw('my value 1')),
value2: indexOf('key2', raw('my value 2'))
or you want to get fancy with composing
source: 'my computed value',
value: hash({
prop1: 'source',
prop2: raw('my raw value')
}) // { prop1: 'my computed value', prop2: 'my raw value' }
implements String.prototype.split()
, allows composing
source: 'val1,val2',
key: ',',
value: split('source', 'key') // ['val1', 'val2']
value: split('source', raw(',')) // ['val1', 'val2']
alias for difference
adds numbers
source1: 1,
source2: 2,
source3: 3,
value1: sum('source1', 'source2', 'source3') // 6
value2: sum('source2', sum('source2', 'source3')) // 6
wraps String.prototype.toLowerCase
, allows composing
originalValue: 'TestString',
newValue: toLower('originalValue') // 'teststring'
wraps String.prototype.toUpperCase
, allows composing
originalValue: 'TestString',
newValue: toUpper('originalValue') // 'TESTSTRING'
wraps Ember.String.underscore
, allows composing
originalValue: 'TestString',
newValue: underscore('originalValue') // 'test_string'