Archive for November, 2012

How not to set Backbone model properties

Posted in Geekdom, Programing on November 29th, 2012 by Jarred – Comments Off on How not to set Backbone model properties

So here is another backbone.js tidbit that took me a while to figure out/understand. This may be fairly straight forward to seasoned programmers, but it really through me for a loop. If you try and set initial model (or view) properties outside of the “defaults” method you can not retrieve them using model.get(‘propertyName’). This was a point of confusion because sometimes it was working like i though it should and sometimes it did not. To further complicate things I was trying to set properties by passing them when I was instantiating the object. It took me a while to figure out what I was doing wrong.

So this is incorrect even though you can still access the object properties.


ExampleModel = Backbone.Model.extend({
propertyName: 'Some Value',
})
exampleModel = new ExampleModel ({propertyName: 'Updated Value'});
exampleModel.propertyName// 'Some Value' not 'Updated Value'

From what I understand this is the correct way to do it


ExampleModel = Backbone.Model.extend({
defaults: {
propertyName: 'Some Value',
},
})
exampleModel = new ExampleModel ({propertyName: 'Updated Value'});
exampleModel.get('propertyName') //'Updated Value'

Now that I understand the concept the documentation makes this very clear to correctly set default model properties using the defaults method.

Problems with binding events on subview in backbone.js

Posted in Programing on November 23rd, 2012 by Jarred – Comments Off on Problems with binding events on subview in backbone.js

I am working on learning backbone.js and well it has been a bumpy road. Along the way I have come across several hiccups, but this one was a doozy and caused me all sorts of frustration. I was trying to to bind a change event to a select menu in one of my subviews. For the life of me I could not get the event to fire correctly. If I copied the exact same event to the parent view it worked just fine. This lead me to believe that I was experience a scope issue. There is lots of information on the web about breaking the scope of “this” in backbone.js which further lead me to believe this was the problem. But turns out that was not the problem at all. After a whole lot of confusion I lucky stumbled upon this post on stackoverflow

Unfortunately it looks like it was not the answer to the original posters problem, but it solved my issue.

According to the post, events in backbone.js are not actually bound to the changing element but rather the root element of the view and then delegated to the children from there. This is important if you are not actually inserting your the root element of your subview into the DOM, because then your events will not fire (which is exactly what I was doing).

So, this render function simply inserts the rendered template html into the DOM which fails to actually insert the views el into the DOM.

render: function() {
$('#anchorDiv').append( this.template(this) );
},

Something like this however will actually insert the view’s root element into the DOM which will (at least in my case) solved all my event issues.
render: function() {
$(this.el).html( this.template(this) );
$('#anchorDiv').append( this.template(this) );
},

I am really liking backbone.js as I think it is helping me better structure my applications. That being said, it has been tough to really learn and grasp how everything is supposed to work. This issue was not straight forward to me at all and hopefully might help somebody out there figure out why their events are not working like they thing they should.

And a few months later…

Posted in Entrepreneurship on November 9th, 2012 by Jarred – Comments Off on And a few months later…

Well, I have not really worked on any of my online project for a few months as my day job (the one that pays better than $1/hour) has been really busy theses past few months. I have not had much time and not really done much in the way of progressing towards my goal. However there are a few noteworthy items to mention. I did spend some time back in Aug. working on the next revision of my Diablo 3 site. So far this site has by far brought in the most income and I think updating it and making it better should be the top priority. As of then my updated version of the site has been sandboxed and is only about half way done. I am trying to figure out how to put the next revision (and final revision) it on google app engine, so that is greatly increasing the time it is taking as I have had to learn how to program in python and learn all sorts of new stuff to get it working.

My income/month has greatly diminished over the past few months and It is mostly because of the diablo 3 site project receiving half as much traffic as it was previously. I think this has a lot to do with the game loosing a lot of its player base (it turns out it was not all that popular of a game for very long). Also, the calculator suffers from inaccuracy issues which might also be causing some of my visitors to not return. While I can not do anything about the game players loosing interest in the game, I can address the accuracy issues in the next version which will hopefully help retain some of my traffic. I would imagine that in the future updates of Diablo 3 game itself (i.e. the inclusion of PVP play) I will see spikes in my traffic which hopefully result in spikes of income.

Income from HTML5 Game portal has slowly been increasing and that gives me a lot of hope that the site will eventually become a good source of revenue. However I am realizing now that fundamentally it requires too much effort to maintain and keep updated. As of now I have to manually review and update each additional game I put on the site and this can be quite time consuming.

I am still hopeful and optimistic about this whole experiment. I have put in a lot of time and effort and I am finally starting to see some results (small). It feels pretty good to know I have not really done anything for the past few months and have still been receiving a few checks in the mail. It feels like “passive” income, even though I know it is an illusion as I have already work for the money. I guess in 10 yrs if the sites are still making money and I have paid myself back for all the time I have spent then I can finally consider it to be truly “passive.”