| By Charles Jolley | Article Rating: |
|
| August 18, 2009 04:30 PM EDT | Reads: |
1,296 |
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,296
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.
- 4th International Cloud Computing Conference & Expo Starts Today
- Rhomobile CEO to Speak at iPhone Developer Summit 2009 West
- Rhomobile to Exhibit at Cloud Computing Conference & Expo
- Adobe Flex Developer Earns $100K in New York City
- Building a Social Site with Ruby and Rails
- Accelerating Innovation with Yahoo! Cloud Serving
- Engine Yard Gets More Money
- JetBrains' IntelliJ IDEA Goes Open Source
- What Could You Do With Your Code in 20 Lines or Less?
- JetBrains Releases RubyMine 2.0
- Engine Yard Closes $19 Million Series C Financing Round
- Coverity Announces the State of Open Source Software Integrity
- 4th International Cloud Computing Conference & Expo Starts Today
- Is Microsoft as Free as Open Source?
- Deploying Azure Hosted Services Should Be as Easy as Deploying a Heroku Application
- Rhomobile CEO to Speak at iPhone Developer Summit 2009 West
- Rhomobile to Exhibit at Cloud Computing Conference & Expo
- Amazon's Virtual Private Cloud Service Goes Live
- Cloud Standards Sought ASAP
- Adobe Flex Developer Earns $100K in New York City
- Building a Social Site with Ruby and Rails
- Accelerating Innovation with Yahoo! Cloud Serving
- Enterprise LAMP Summit Asks Global Open Source Leaders “Can LAMP Deliver?”
- Engine Yard Gets More Money
- Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?
- Ruby on Rails Won't Make It in 2007 and Forget About AJAX
- The Top 250 Players in the Cloud Computing Ecosystem
- The Jury's Still Out On Ruby On Rails (RoR) and AJAX
- Red Hat Named "Platinum Sponsor" of Virtualization Conference & Expo
- Can Ruby Live Without Rails?
- An Introduction to Ant
- Testing in Ruby on Rails
- Ruby On Rails Moves At 'Acela' Rates Toward Java
- Java Kicks Ruby on Rails in the Butt
- Cyberhive Supports Ruby On Rails
- Ruby on Rails One-Day Seminar: Introducing Ruby on Rails – the Pain-Killer for Web Developers




































