Public API alternative to __registry__.knownForType?


#1

Hi, Folks!

I have an app that contains many lessons, which, in turn, contain many slides. I have a service (see below) that keeps track of how many slides each lesson has by introspecting the registry to see how many slide templates exist for that lesson. Is there a way to do this via a public API, instead of using __registry__.knownForType?

# app/services/session.coffee
`import Ember from "ember";`
`const { getOwner } = Ember;`

Session = Ember.Service.extend
  lessonNumber: 1

  slides: ( ->
    templates = getOwner(this).__registry__.knownForType("template")
    templateNames = Object.keys(templates)
    slideNames = templateNames.map (templateName) =>
      match = templateName.match(new RegExp("slides/#{@lessonNumber}/(\\d+)$"))
      match[1] if match
    slideNames.filter (slideName) ->
      Ember.isPresent(slideName)
  ).property()

Thanks for your time!