Skip to content

kellyselden/ember-awesome-macros

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ember-awesome-macros

npm version Build Status Dependency Status devDependency Status

Usage

ember install ember-awesome-macros
import nameOfMacro from 'ember-awesome-macros/name-of-macro';

Macro list

  • defaultTrue
  • getBy
  • join
  • peekQueue
  • peekStack
  • promiseAll
  • promiseArray
  • promiseHash
  • promiseObject
  • toLower
  • toUpper

Details

defaultTrue

sugar for ifNull('key', true) from ember-cpm

getBy

get a variable property name from an object

key: 'modelProperty',
model: {
  modelProperty: 'my value'
},
value: getBy('model', 'key') // "my value"
join

join a computed array

values: Ember.A(['1', '2']),
valuesString: join('values', ', ') // "1, 2"
peekQueue

get the first item of an array

values: Ember.A(['1', '2']),
firstValue: peekQueue('values') // "1"
peekStack

get the last item of an array

values: Ember.A(['1', '2']),
firstValue: peekStack('values') // "2"
promiseAll

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']
promiseArray

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')
promiseHash

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' }
promiseObject

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')
toLower

calls toLowerCase on your string

originalValue: 'abcZXY',
newValue: toLower('originalValue') // "abcxyz"
toUpper

calls toUpperCase on your string

originalValue: 'abcZXY',
newValue: toUpper('originalValue') // "ABCXYZ"