ember install ember-awesome-macros
import nameOfMacro from 'ember-awesome-macros/name-of-macro';
defaultTrue
getBy
join
peekQueue
peekStack
promiseAll
promiseArray
promiseHash
promiseObject
toLower
toUpper
sugar for ifNull('key', true)
from ember-cpm
get a variable property name from an object
key: 'modelProperty',
model: {
modelProperty: 'my value'
},
value: getBy('model', 'key') // "my value"
join a computed array
values: Ember.A(['1', '2']),
valuesString: join('values', ', ') // "1, 2"
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"
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')
calls toLowerCase
on your string
originalValue: 'abcZXY',
newValue: toLower('originalValue') // "abcxyz"
calls toUpperCase
on your string
originalValue: 'abcZXY',
newValue: toUpper('originalValue') // "ABCXYZ"