Download qooxdoo Documentation
Transcript
qooxdoo Documentation, Release 1.2
We want the data to be available as a property on our own service object. First, we need to add a property definition
to the TwitterService.js file. As with the events specification, the property definition goes alongside with the
members section:
properties : {
tweets : {
nullable: true,
event: "changeTweets"
}
},
We named our property tweets and added two configuration keys for it:
• nullable describse that the property can be null
• event takes the name of the event fired on a change of the property
The real advantage here is the event key which tells the qooxdoo property system to fire an event every time the
property value changes. This event is mandatory for the whole data binding we want to use later. But that’s it for
setting up a property. You can find all possible property keys in the documentation.
Now we need to connect the property of the store with the property of the twitter service. That’s an easy task with the
single value binding included in the qooxdoo data binding. Just add the following line after the creation of the data
store:
this.__store.bind("model", this, "tweets");
This line takes care of synchronizing the two properties, the model property of the store and the tweets property of
our service object. That means as soon as data is available in the store, the data will also be set as tweets in the twitter
service. Thats all we need to do in the twitter service class for fetching the data. Now its time to bring the data to the
UI.
Bring the tweets to the UI
For that task we need to go back to our Application.js file and create an instance of the new service:
var service = new twitter.TwitterService();
You remember the debug listener we added in the last tutorial? Now we change the reload listener to fetch the tweets:
// reload handling
main.addListener("reload", function() {
service.fetchTweets();
}, this);
Thats the first step of getting the data connected with the UI. We talk the whole time of data in general without even
knowing how the data really looks like. Adding the following lines shows a dump of the fetched data in your debugging
console.
service.addListener("changeTweets", function(e) {
this.debug(qx.dev.Debug.debugProperties(e.getData()));
}, this);
Now it’s time for a test. We added a new classes so we need to invoke the generator and load the index file of the
application. Hit the reload button of the browser and see the data in your debugging console. The important thing you
should see is that the data is an array containing objects holding the items we want to access: the twitter message as
text and "user.profile_image_url" for the users profile picture. After evaluating what we want to use, we
can delete the debugging listener.
22
Chapter 2. Getting Started