Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Adding declarative bindings for Controllers, Models, Collections, and CollectionViews#789

Open
albatrocity wants to merge 2 commits into
chaplinjs:masterfrom
cremalab:listen-to-hash-controllers-models
Open

Adding declarative bindings for Controllers, Models, Collections, and CollectionViews#789
albatrocity wants to merge 2 commits into
chaplinjs:masterfrom
cremalab:listen-to-hash-controllers-models

Conversation

@albatrocity

Copy link
Copy Markdown

delegateListeners and delegateListener have been moved to the EventBroker so that all classes that mix it in can define a listen object to define event listeners. The delegateListeners method is called in the constructor of Views, Models, Collections, and Controllers. Basically applying #419 to the other basic Chaplin classes.

The motivation behind this was so I could do:

class ThingController extends Controller
  listen:
    'saveThing mediator': 'update'

  update: (model) ->
    model.save
      success: =>
        @redirectTo 'things'

instead of:

class ThingController extends Controller
  initialize: ->
    super
    @subscribeTo 'saveThing', @update

  update: (model) ->
    model.save
      success: =>
        @redirectTo 'things'

I do this a lot and overriding initialize was starting to feel dirty 😄

@Sija

Sija commented Apr 26, 2014

Copy link
Copy Markdown
Contributor

👍

@jeron-diovis

Copy link
Copy Markdown

Oh, it's cool! Let's be more declarative.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants