سؤال

I currently trying out ChaplinJS for a new project and I'm running into a problem.

I want to have a controller (for my navigation) that's listening to the changes of the router. I want to have callbacks for events like changeURL or route. I'm not sure how Chaplin's mediator works but I thought the router is throwing events using the mediator which I should be able to catch. I tried this:

mediator = require 'mediator'
Controller = require 'controllers/base/controller'
Menu = require 'models/menu'
MenuView = require 'views/menu-view'

module.exports = class MenuController extends Controller
    listen:
        'router:changeURL mediator': @test

    initialize: ->
        super

        @menu = new Menu()
        @view = new MenuView model: @menu

        mediator.subscribe 'router:changeURL', @test

    test: ->
        console.log 'testlisten'
هل كانت مفيدة؟

المحلول

You should use beforeAction method to accomplish this.

The method receives all arguments actions receive. http://docs.chaplinjs.org/chaplin.controller.html

There is no listen in controllers.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top