Nick Dima
Nick Dima

Reputation: 1595

Chaplin js permanent controller that responds to routes

Is it possible to have a controller that keeps its state alive and also responds to routes?
For example I would have a PlayerController that I initiate in the application's initControllers method and then I will need it also to respond to a route like /player/trackID so I can change the current playing track.

Upvotes: 0

Views: 271

Answers (1)

Nitin Arora
Nitin Arora

Reputation: 2668

Yes, you can create a controller which will be active for the lifetime of the application. As you mentioned instantiate PlayerController in initControllers method of the application and in routes.js define the route /player/:trackID to be bound to a specific method of the PlayerController.

e.g. route in routes.js will look like

match('player/:trackID', 'player#playTrack', {name:'playtrack'});

In the above route playTrack is the method of PlayerController.

Upvotes: 1

Related Questions