FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August...

33
FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013

Transcript of FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August...

Page 1: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

FlexJS: Deeper DiveUnder the hood of the FlexJS framework

Alex HaruiApache Flex PMC Chair

August 4, 2013

Page 2: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

Who am I?

• One of the original Flex SDK developers at Macromedia

• VP of Apache Flex

• Apache Flex PMC Chair

• 30+ years experience

• 11+ years at Macromedia/Adobe

Page 3: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

Disclaimer

• Even though I am a full-time Adobe employee and spend my whole day on Apache Flex, everything I say here is just my opinion, and not an official statement on behalf of Adobe Systems Inc., or the Apache Software Foundation, or even the Apache Flex project itself.

Page 4: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

FlexJS

• Use MXML and ActionScript to create either SWFs that run in Flash/AIR or HTML/JS/CSS files that run in browsers (or anywhere HTML/JS/CSS runs) without Flash.• IE8, 9, 10, Chrome, Firefox, Android, IOS• Mobile Apps via PhoneGap/Apache Cordova

Page 6: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

Terminology

• API Surface – The total set of public properties, methods and events on a component

• Component Developer – Someone who is developing components for use by an Application Developer

• Application Developer – Someone who is building an Application by taking a set of components and gluing them together with ActionScript.

Page 7: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

More Terminology

• Falcon – The name for the code-base for Adobe’s ASC2.0 that was donated to Apache Flex.

• FalconJS – The cross-compiler based on Falcon that was donated by Adobe to Apache Flex. Early prototypes used this compiler, but this code base is not under development at this time.

• FalconJX – A cross-compiler developed by Apache Flex committers that is currently being used to compiler FlexJS applications.

Page 8: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

Philosophy

• Parallel Frameworks

• Plug-ins

• Composition over Inheritance

• Multiple Component Sets

• Just-in-time, not Just-in-case

• Rapid prototyping is important, but end-game optimization is critical

Page 9: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

Parallel Frameworks

• The component developer does the hard work:• Creates both a button.as and button.js• Essentially, writes the component twice, once

in AS and once in JS.• Button.as can use Flash APIs• Button.js uses HTMLElements, JS, and CSS

• The application developer writes one set of code• Compiles and debugs in Flash• Cross-compiles to HTML/JS/CSS

Page 10: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

Beads (Plug-Ins)

• Instead of one Button with every property imaginable, Button optional properties are packaged into “Beads”.

• Beads are the name for plug-ins• They should be highly-reusable• Prompt for TextArea, TextInput, ComboBox, for

example.

• Component when used as sub-components don’t need as much as when used at top-level• Border on TextInput in ComboBox

Page 11: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

Beads (cont’d)

• Different code for different runtime environments• Toss out mouseover code on mobile, swap in

touch code instead

• Use CSS to choose beads

• Wrap up a bunch of beads into a top-level component and proxy the model to the component API surface

Page 12: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

Composition

• JIT compilers are used in the runtimes.• The more you re-use code, the more efficient

JIT is• Flex startup is actually faster without JIT

because it doesn’t re-use as much code

• A single feature can be written once and applied in several places.• Text prompt example

Page 13: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

Multiple Component Sets

• A one-size-fits-all Button works in most places, but not all

Page 14: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

Multiple Component Sets

• A one-size-fits-all Button works in most places, but not all

Page 15: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

Multiple Component Sets

• A one-size-fits-all Button works in most places, but not all

• A choice of Buttons means you have more decisions to make, but you don’t have to carry around excess code.

• And some folks have requirements to use JQuery or other frameworks.

Page 16: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

Prototyping vs Optimization

• How do you choose from so many different buttons?• Need utility to help you choose• Maybe a few heavy buttons with lots of

options baked in

• You will be able to toss out code you are not using.

• Debug-mode beads can give more warnings and do more parameter checking.

Page 17: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

Just-in-Time

• Flex initializes a bunch of managers at startup that prepare for overlapping top-level windows, tooltips, and custom cursors.• None of these are likely to be found in mobile

apps• You don’t even need PopUpManager unless

you have floating non-modal popups

• Choose the right PopUpManager, and only instantiate it when you actually get around to showing a popup.

Page 18: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

Component Patterns

• MVC• Model Bead – stores properties• Spark model is baked into the component

• View Bead – assembles sub-components, if any• Spark Skins combine sub-components and the

actual visuals

• Controller Bead – manages events, updates model and dispatches other events

Page 19: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

Button.as

• Has no model. There are no properties!

• CSS for Button specifies a ButtonView as the view.

• ButtonView.as only knows how to display whatever is specified by the background-image style.• That’s what the HTML Button does so that

what we’ll encapsulate and present in AS.• Flex buttons used for scrollbar arrows still

think about text label layout. That’s not pay-as-you-go.

Page 20: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

TextButton.as

• Wrapper that proxies label property to model.

• CSS for Button specifies model with label property.

• ButtonView.as only knows how to display the label.• Different ButtonView could know how to

display an icon with a label.• Then you’d use a different model as well that

supports an “icon” property or style.

Page 21: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

Button.js

• Thin wrapper around HTML Button element

• TextButton.js is same since text behavior is built-in to HTML.

Page 22: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

Button Skin

• For the basic component set, the skins are images you can specify as a background-image in HTML.• Gif, png, jpg• They are loaded on the fly, no embedding

• But the HTML5 Button set can load SVG as background-image

• You choose different components sets based on target devices.

Page 23: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

Panel.as

• Specifies a PanelView that creates a TitleBar and ContentPane

• Another PanelView would create a TitleBar, ContentPane and ControlBar.• Other PanelViews would include a StatusBar

• TitleBar is a Sprite with a TextField• Some other TitleBar could be a Sprite with FTE

Text

Page 24: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

Panel.js

• Also specifies a PanelView. This one also creates a TitleBar and ContentPane.

• TitleBar is a DIV with some text in it.

Page 25: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

TextPromptBead.as

• Overlays Text widget

• Different TextPromptBead can have different strategy for when to appear/disappear/reappear.

• Different implementation could change styles and text in a single text widget.

Page 26: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

CSS in FlexJS

• CSS compliant• Custom properties are prefixed• AS-only properties are hidden in a custom

media type in a media query.

• Need to create more and more sophisticated CSS implementations in the AS side

Page 27: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

ValuesManager

• Abstraction for getting default values.• CSS Styles, Resources, etc.

• If your app doesn’t use an expensive CSS feature, you may choose a less expensive ValuesManager

Page 28: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

Compiling and Linking

• A Flex project contains MXML, AS, and SWCs

• The Compiler creates compilation units for every class defined in MXML, AS and SWCs

• FalconJX generates JS only for MXML and AS classes.• It assumes that external JS files exist for every

class in a SWC.

Page 29: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

Block Diagram

ApplicationMXML& AS

Button.as(SWC)

HTTPService.as(SWC)

Falc

on

SWF

Page 30: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

Block Diagram

ApplicationMXML& AS

Button.as(SWC)

HTTPService.as(SWC)

Falc

onJX

JS

Button.js

HTTPService.js

GoogleClosure

Page 31: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

Next Steps

• More components

• More compiler work• Metadata• Interfaces and other introspection

• Release early versions• Basic features first, more features later• Over time, we should be able to replicate most

but not all of the current Flex SDK APIs

Page 32: FlexJS: Deeper Dive Under the hood of the FlexJS framework Alex Harui Apache Flex PMC Chair August 4, 2013.

Summary

• We need help!• All kinds of contributions welcome• Testing• Development• Documentation• Examples

• Look for me in the Apache Flex Discovery Room and on the Apache mailing lists.