Add indexer service (equivalent of Dereferencer, but named more accurately)

This commit is contained in:
Rohan Mitchell
2014-11-20 12:25:24 +11:00
parent 680ba379c1
commit 7069b30e71
2 changed files with 26 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
# Convert an array of objects into a hash, indexed by the objects' ids
#
# producers = [{id: 1, name: 'one'}, {id: 2, name: 'two'}]
# Indexer.index producers
# -> {1: {id: 1, name: 'one'}, 2: {id: 2, name: 'two'}}
angular.module("ofn.admin").factory 'Indexer', ->
new class Indexer
index: (data) ->
index = []
for e in data
index[e.id] = e
index