| By Charles Jolley | Article Rating: |
|
| August 18, 2009 04:30 PM EDT | Reads: |
1,295 |
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,295
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.
- 1st Annual Government IT Conference & Expo: Themes & Topics
- Cloud Computing on Gartner's Top 10 List and SYS-CON Events' 2010 Calendar
- IBM, Microsoft, Others in Lock-Picking Cloud API Push
- RothmanResearch.com Market Review and Company Analysis on FULT, DISH, ASBC, CTRP, FSLR and CRBC
- Yahoo! Query Language
- United Planet offers practical portal building tips for SMBs
- Stock in Focus: Sunwin International Neutraceuticals
- The Time Is Right for Enterprise Cloud Computing
- The Bunker achieves PCI DSS Compliance
- Qt DevDays 2009 - Munich
- Testing the Limits with Jack Margo SVP of Developer Shed, (part 1)
- Excuse Me But Is That a Gazebo On Your Site?!
- 1st Annual Government IT Conference & Expo: Themes & Topics
- Cloud Computing on Gartner's Top 10 List and SYS-CON Events' 2010 Calendar
- Is Microsoft as Free as Open Source?
- The Curious Case of Build Release Management eBook
- Cloud Security Is Nothing New but It Changes Everything!
- IBM, Microsoft, Others in Lock-Picking Cloud API Push
- Research and Markets: Global Developer Population and Demographic Study 2009, V1 Will Estimate Specific Developer Target Markets' Size
- RothmanResearch.com Market Review and Company Analysis on FULT, DISH, ASBC, CTRP, FSLR and CRBC
- Yahoo! Query Language
- United Planet offers practical portal building tips for SMBs
- Stock in Focus: Sunwin International Neutraceuticals
- The Time Is Right for Enterprise Cloud Computing
- Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?
- The Top 250 Players in the Cloud Computing Ecosystem
- Red Hat Named "Platinum Sponsor" of Virtualization Conference & Expo
- Ulitzer to Give Drupal 6.0 Its Biggest Scalability Challenge Yet
- An Introduction to Ant
- Appcelerator Named "Platinum Sponsor" of AJAX World Conference & Expo
- "What's New and Exciting About the Web Right Now?" Asks Time Magazine
- Oracle To Keynote Cloud Computing Expo
- First Eclipse Project Targeting PHP Now Available
- AJAX World - Two Great PDF Creators
- C#, Turbo Pascal, C++, PHP...and the LEGO Brick: Denmark's Leading Exports
- Rolling Your Own MVC: The Page Load Scenario
































