| By Charles Jolley | Article Rating: |
|
| August 18, 2009 04:30 PM EDT | Reads: |
1,298 |
One of the coolest parts of the new SproutCore View layer is its ability to use aspect-based programming to add behaviors to views.
Aspect-based programming is built on the premise that often objects that don’t follow from the same class hierarchy may in fact need similar behaviors.
This is especially true in GUI programming when designers come to you and say something like “I came up with this new widget - it looks kind of like a progress bar but it acts like a button when you click on it”.
In SproutCore, you capture these common behaviors in a “mixin”. A mixin is just a collection or properties and methods that are added to your class when you define it. The view layer will actually look for specific hooks on your mixin so that you can automatically hook into the drawing engine, listen for events, etc. It’s very powerful.
Take the example above: with the button-y progress bar. SproutCore has an SC.Button mixin that implements button-like behavior. Just apply it to an SC.ProgressView and update a few hooks to get the API you want.
MyApp.ProgressButton = SC.ProgressView.extend(SC.Button, {
// ... extra properties here
});
SproutCore comes with built in aspects that implement most of its common APIs including managing content properties (SC.Control, SC.ContentDisplay), rendering (SC.Border, SC.Shadow), and some behaviors (SC.Button).
Over time I expect we’ll add more. In the mean time, this is a great technique to learn to rapidly build high-quality views with composite behaviors without having to rewrite code.
If you want a further example of how mixins can be used, take a look at this tutorial by FrozenCanuck on using the SC.ContentDisplay mixin to easily auto-render a bunch of properties on a content object.
Read the original blog entry...
Published August 18, 2009 Reads 1,298
Copyright © 2009 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Charles Jolley
Charles Jolley is the creator of SproutCore and CEO of Sproutit, which provides consulting and software services for building SproutCore applications on the web. He has helped build some of the most popular RIAs on the web today.
- GITEX TECHNOLOGY WEEK 2009 Exhibitor Profiles
- IBM’s Linux-Based ‘Cloud-in-a-Box’ Makes its First Sale
- United Planet offers practical portal building tips for SMBs
- Unlocking the Cloud with Enterprise Private PaaS
- The Power of Google and the Promise of Cloud Computing
- Developing APIs for the Cloud
- The Bunker achieves PCI DSS Compliance
- Qt DevDays 2009 - Munich
- Testing the Limits with Jack Margo SVP of Developer Shed, (part 1)
- Big Data Kills 30-Year-Old Market
- Excuse Me But Is That a Gazebo On Your Site?!
- Securing the Cloud and Establishing a Level of Trust
- GITEX TECHNOLOGY WEEK 2009 Exhibitor Profiles
- Is Microsoft as Free as Open Source?
- IBM’s Linux-Based ‘Cloud-in-a-Box’ Makes its First Sale
- Research and Markets: Global Developer Population and Demographic Study 2009, V1 Will Estimate Specific Developer Target Markets' Size
- United Planet offers practical portal building tips for SMBs
- (Database - Sun) + Oracle = Acquisition
- Unlocking the Cloud with Enterprise Private PaaS
- The Power of Google and the Promise of Cloud Computing
- Developing APIs for the Cloud
- The Bunker achieves PCI DSS Compliance
- What Will the Car of the Future Look Like? Delphi Highlights Technologies That Are Enhancing Vehicle Connectivity
- Qt DevDays 2009 - Munich
- The Top 250 Players in the Cloud Computing Ecosystem
- Red Hat Named "Platinum Sponsor" of Virtualization Conference & Expo
- An Introduction to Ant
- Google Web Toolkit: Finally Java Has Been Put into JavaScript!
- AJAX World RIA Conference News - AJAX & RIA with Server-Side JavaScript
- Python Creator Guido van Rossum to Present the Next-Generation Python 3000
- White Paper: "Extended Validation SSL Certificates"
- CEO of Hyperic, Javier Soltero on SYS-CON.TV
- Perforce Software Delivers State-of-the-Art Application Lifecycle Management
- Rating JRuby, Jython, and Groovy on the Java Platform
- TurboGears - Python-Based Framework for AJAX Web Development
- iPhone 3G Only Looks Cheaper



































