| By Charles Jolley | Article Rating: |
|
| August 18, 2009 04:30 PM EDT | Reads: |
8,362 |
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 8,362
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.
- Cloud People: A Who's Who of Cloud Computing
- North Bridge Joined by 56 Cloud Leaders to Launch Third Annual Future of Cloud Computing Survey
- ActiveState Acquires Appsecute: Private-PaaS Leader Purchases Social DevOps Solutions Provider
- ActiveState Grows Stackato Partner Program
- Wurldtech Appoints Stephen Munford to Board of Directors
- Cloud People: A Who's Who of Cloud Computing
- Platform as a Service (PaaS) Market - Global Advancements, Business Models, Technology Roadmap, Worldwide Market Forecasts & Analysis (2013 - 2018)
- Platform as a Service (PaaS) Market - Global Advancements, Business Models, Technology Roadmap, Worldwide Market Forecasts & Analysis (2013 - 2018)
- ActiveState Named a Gartner Research "Cool Vendor in PaaS"
- North Bridge Joined by 56 Cloud Leaders to Launch Third Annual Future of Cloud Computing Survey
- ActiveState Connects Stackato to Oracle
- ActiveState Acquires Appsecute: Private-PaaS Leader Purchases Social DevOps Solutions Provider
- ActiveState Grows Stackato Partner Program
- Wurldtech Appoints Stephen Munford to Board of Directors
- Cloud People: A Who's Who of Cloud Computing
- Red Hat Named "Platinum Sponsor" of Virtualization Conference & Expo
- Cloud Expo New York Call for Papers Now Open
- An Introduction to Ant
- Cloud Expo 2011 East To Attract 10,000 Delegates and 200 Exhibitors
- Cloud Expo, Inc. Announces Cloud Expo 2011 New York Venue
- The Cloud Bubble: Is Computing Becoming a Utility?
- Telco Perl Powers Telephony With Linux
- Cloud Computing Bootcamp May 18-19 in Prague, Czech Republic
- This Man Should Be Fired from His Job as a Magazine Editor
- How To Use Social Media in Your Job Search
- Rackspace Cloud APIs Open Sourced








With Cloud Expo New York | 12th Cloud Expo [J...













