Skip to content
This repository has been archived by the owner on Mar 20, 2021. It is now read-only.

Allow events hash definitions on arbitrary view data objects #362

Open
finpingvin opened this issue May 2, 2014 · 2 comments
Open

Allow events hash definitions on arbitrary view data objects #362

finpingvin opened this issue May 2, 2014 · 2 comments
Labels
Milestone

Comments

@finpingvin
Copy link

In our project we have views that uses more than one model, because some models contains state that are shared across the application.
It would be convenient to gain access to dataObject(), so that we can implement behaviour for these custom model attributes that mimics those of the standard "model" and "collection" attributes.

An example of how this could work:

SomeView = Thorax.View.extend({
  events: {
    model: {
      sync: function() {console.log('model synced')}
    }
    sharedState: {
      'change:someSharedData': function() {console.log('sharedState changed someSharedData')}
    }
  }
})
Thorax.dataObject('sharedState', {set: 'setSharedState'})

sharedState = new Thorax.Model({someSharedData: 3})
new SomeView({sharedState: sharedState})
sharedState.set('someSharedData', 4)
// prints out "sharedState changed someSharedData"

Or do you have another suggestion on how to approach this?

@kpdecker
Copy link
Contributor

The desire here is to be able to bind specific event handlers to a specific data object when using multiple?

@finpingvin
Copy link
Author

I'm not certain that I interperet your question right, but the desire is, since we often use multiple models/collections per view, to bind events to all models/collections in the same manner.
And I like the idea of using the events-hash. A quick glance on the events-hash gives you a fair idea of what happens during the lifecycle of a view.
To be able to assign dataObjects per view (in contrast to all views, as dataObject() does currently) would also be more clean IMO if you choose to pursue this route.

What's your thoughts?

@kpdecker kpdecker changed the title Gain access to dataObject() Allow events hash definitions on arbitrary view data objects Nov 30, 2014
@kpdecker kpdecker added this to the 3.1 milestone Nov 30, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

2 participants