mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-07 22:46:06 +00:00
16 lines
616 B
CoffeeScript
16 lines
616 B
CoffeeScript
Darkswarm.factory 'Enterprises', (enterprises, CurrentHub, Dereferencer)->
|
|
new class Enterprises
|
|
enterprises_by_id: {} # id/object pairs for lookup
|
|
constructor: ->
|
|
@enterprises = enterprises
|
|
for enterprise in enterprises
|
|
@enterprises_by_id[enterprise.id] = enterprise
|
|
@dereference()
|
|
|
|
dereference: ->
|
|
if CurrentHub.hub?.id
|
|
CurrentHub.hub = @enterprises_by_id[CurrentHub.hub.id]
|
|
for enterprise in @enterprises
|
|
Dereferencer.dereference enterprise.hubs, @enterprises_by_id
|
|
Dereferencer.dereference enterprise.producers, @enterprises_by_id
|