Dev question - setTopicController event removed.

Quick question guys:

We were using

 TopicRoute.on("setupTopicController", function(event) {
   topicController = event.controller
 })

in a plugin’s -init.js to get access to the postStream’s “hasNoFilters” attribute.
This has been removed in commit 6381170 (https://github.com/discourse/discourse/commit/63811707e8e02fce8ec2796d72ebdf807a5396ea), and now we’re not sure how to get at that attribute anymore.

Full context:

import { withPluginApi } from 'discourse/lib/plugin-api'
import TopicRoute from 'discourse/routes/topic'

function initializePlugin(api) {
let topicController;

  TopicRoute.on("setupTopicController", function(event) {
    topicController = event.controller
  })

  api.addPostMenuButton('iso', attrs => {

    return {
      action: 'clickIso',
      icon: topicController.get("model.postStream.hasNoFilters") ? 'user' : 'users',
      title: topicController.get("model.postStream.hasNoFilters") ? 'iso.title' : 'unisoed.title',
      position: 'second'
    }
  })

  api.attachWidgetAction('post-menu', 'clickIso', function() {
      if(topicController.get("model.postStream.hasNoFilters")) {
        const postStream = topicController.get("model.postStream");
        postStream.toggleParticipant(this.attrs.username)
          .then(() => postStream.refresh())
          .then(() => topicController.send("jumpToPostId", this.attrs.id));
      }
      else {
        const postStream = topicController.get("model.postStream");
        postStream.cancelFilter();
        postStream.refresh()
          .then(() => topicController.send("jumpToPostId", this.attrs.id));
      }
  })
}

export default {
  name: 'iso-button',
  initialize: function() {
    withPluginApi('0.8.6', api => initializePlugin(api))
  }
}

Replace the replace the TopicRoute.on block with this

TopicRoute.reopen({
    setupController(controller, model) {
      this._super(controller, model);
      topicController = controller;
    }
  });

Should work but there should be a better way to handle this for sure I guess.

js is maybe one of the few or the only language such a thing works.

Hmm I made the replacement and it’s still broken, will look into further.

Made a PR here, with a bit of explanation of what’s going on:

https://github.com/kcereru/iso/pull/2

Interesting. So resolver gives out an instance and not a class? Interesting.

Also, we could simplify this code further by using api._lookupContainer?

Yup, that’s right. (although technically ember doesn’t have classes, it has “Factories”. This is why you’ll see lookupFactory and function names like that).

Yup, good point. Technically it’s not part of the api, but that’s a better simpler approach than using the container passed to the initializer.