SlideShare a Scribd company logo
1 of 23
Download to read offline
Appcelerator Alloy MVC
tiConf Dhaka, Bangladesh
Feb 10th, 2015
Fokke Zandbergen
@FokkeZB
Show your hand if you know
a programming language
✌
Show your hand if you've used
HTML & CSS
✌
Show your hand if you’ve used
JavaScript
✌
Show your hand if you’ve used
Titanium
✌
Classic app.js
var window = Ti.UI.createWindow({
backgroundColor: “white"
});
var label = Ti.UI.createLabel({
text: “Hello World”
});
label.addEventListener(“click”,
function open() {
alert(“Hello World”);
}
);
window.add(label);
window.open();
style
logic
markup
logic
markupmarkup
spaghetti code
© Sira Hanchana
Alloy
<Alloy>
<Window>
<Label onClick=”open”>Hello World</Label>
</Window>
</Alloy>
”Window”: {
backgroundColor: “white”
}
function open() {
alert(“Hello World”);
}
$.index.open();
index.xml
index.tss
index.js
Familiar
• HTML-like XML
• CSS-like TSS
• JavaScript
• No HTML UI
• No overhead
• Compiles to Classic
…but better
Compiled simplified
module.exports = function Controller() {
var $ = this;
$.index = Ti.UI.createWindow({
backgroundColor: “white”
});
$.__alloyId1 = Ti.UI.createLabel({
text: “Hello World”
});
$.__alloyId1.addEventListener(“click”, open);
$.index.add($.__alloyId1);
function open() {
alert(“Hello World”);
}
$.index.open();
};
index.tss
index.xml
index.js
Structure simplified
▾ app
▾ assets
▾ images

logo.png
▾ controllers
index.js
▾ lib
utils.js
▾ styles
index.tss
▾ views
index.xml
▾ widgets
alloy.js
config.json
tiapp.xml
▸ app
▾ Resources
▾ alloy
▾ controllers
index.js
backbone.js
CFG.js
underscore.js
▾ images
logo.png
alloy.js
app.js
utils.js
tiapp.xml
▾ Resources
▾ images
logo.png
app.js
main.js
utils.js
tiapp.xml
deep dive
© Melissa
Classes, ids and tags
<Alloy>
<Window>
<Label id=”lbl” class=”red big”>Hello</Label>
</Window>
</Alloy>
index.xml
”Window”: { backgroundColor: “white” }
”#lbl”: { backgroundColor: “green” }
”.red”: { color: “red” }
”.big”: { font: { fontSize: 20 }
”.bold”: { font: { fontWeight: ”bold” }
$.index.open();
$.lbl.text = “bye”;
$.addClass($.lbl, “bold”);
index.tss
index.js
Conditional code
<Alloy>
<Label platform=”ios,!android”>iOS, Windows</Label>
<Label formFactor=”handheld”>Handheld</Label>
<Label if=”Alloy.Globals.iOS8”>iOS 8</Label>
</Alloy>
”Label[platform=ios,!android formFactor=tablet]”: {
color: “red”
}
”Label[if=Alloy.Globals.iOS8]”: {
backgroundColor: “green”
}
if (OS_IOS && ENV_PRODUCTION && DIST_STORE) {
alert(“iOS App Store, not Ad Hoc”);
}
index.xml
index.tss
index.js
if (OS_IOS && ENV_TEST && Alloy.CFG.foo !== 7) {
alert(“Wrong!”);
}
Conditional config
{
"global": {"foo":1},
"env:development": {"foo":2},
"env:test":{"foo":3},
"env:production":{"foo":4},
"os:ios env:production": {"foo":5},
"os:ios env:development": {"foo":6},
"os:ios env:test": {"foo":7},
"os:android":{"foo":8},
"os:mobileweb":{"foo":9},
"dependencies": {
“com.foo.widget":"1.0"
}
}
config.json > CFG.js
index.js
Global namespace
var uuid = Ti.Platform.createUUID(); // wrong
(function(global) {
var version = Ti.Platform.version; // safe
Alloy.Globals.iOS8 = version.split(“.”)[0] === ”8”;
global.started = Ti.Platform.createUUID(); // avoid
Alloy.Globals.seed = Ti.Platform.createUUID(); // better
})(this);
alloy.js > app.js
module.exports = {
seed: Ti.Platform.createUUID(); // best
};
utils.js
Data binding
<Alloy>
<Collection src=”album” />
<TableView dataCollection=”album”
dataTransform=”transformer”
dataFilter=”filter”>
<TableViewRow title=”{title} by {artist}” />
</TableView>
</Alloy>
index.xml
function filter(collection) {
return collection.where({artist:”Beatles”});
}
function transformer(model) {
var tf = model.toJSON();
tf.title = tf.title.toUpperCase();
return tf;
}
index.js
Themes
• Set in config.json
• Overwrites assets
• Merges styles
• Merges config
▾ app
▾ assets
▾ images

logo.png
▸ controllers
▾ styles
index.tss
▸ views
▾ themes
▾ green
▾ assets
logo.png
▾ styles
index.tss
config.json
config.json
whitelabelapps
Widgets
▾ app
▸ assets
▸ lib
▸ controllers
▸ styles
▸ views
▾ widgets
▸ mine
▸ assets
▸ lib
▾ controllers
widget.tss
▸ styles
▸ views
widget.json
config.json
<Alloy>
<Require src=”foo” />
<Widget src=”mine” />
<Widget src=”mine” name=”bar” />
</Alloy>
• apps in apps
• 400+ open source
• theme-able!
what’s coming?
© Ron Jones
Alloy 1.6.0 (Q1)
• Support for Windows Phone
• Support for promises in sync adapters
• Upgrade Backbone 0.9.2 > 1.1.2
• Upgrade Underscore 1.4.4 > 1.6.0
• Support for two-way-data-binding via Nano
• More than 25 other fixes/improvements
© Saint Bernadine Mission Communications Inc.
Q
If you know JS, HTML & CSS
You can build native apps with Alloy

More Related Content

What's hot

React Nativeアプリをリリースし続けるために、最初に行う8つの取り組み
React Nativeアプリをリリースし続けるために、最初に行う8つの取り組みReact Nativeアプリをリリースし続けるために、最初に行う8つの取り組み
React Nativeアプリをリリースし続けるために、最初に行う8つの取り組みYukiya Nakagawa
 
Cross-platform Native App ontwikkeling met Appcelerator
Cross-platform Native App ontwikkeling met AppceleratorCross-platform Native App ontwikkeling met Appcelerator
Cross-platform Native App ontwikkeling met AppceleratorFokke Zandbergen
 
An introduction to PhantomJS: A headless browser for automation test.
An introduction to PhantomJS: A headless browser for automation test.An introduction to PhantomJS: A headless browser for automation test.
An introduction to PhantomJS: A headless browser for automation test.BugRaptors
 
Automatic Functional Testing with Selenium and SauceLabs
Automatic Functional Testing with Selenium and SauceLabsAutomatic Functional Testing with Selenium and SauceLabs
Automatic Functional Testing with Selenium and SauceLabsJoseph Chiang
 
Enterprise AIR Development for JavaScript Developers
Enterprise AIR Development for JavaScript DevelopersEnterprise AIR Development for JavaScript Developers
Enterprise AIR Development for JavaScript DevelopersAndreCharland
 
探討Web ui自動化測試工具
探討Web ui自動化測試工具探討Web ui自動化測試工具
探討Web ui自動化測試工具政億 林
 
High Performance JavaScript (CapitolJS 2011)
High Performance JavaScript (CapitolJS 2011)High Performance JavaScript (CapitolJS 2011)
High Performance JavaScript (CapitolJS 2011)Nicholas Zakas
 
Detecting headless browsers
Detecting headless browsersDetecting headless browsers
Detecting headless browsersSergey Shekyan
 
Web20expo 20080425
Web20expo 20080425Web20expo 20080425
Web20expo 20080425Media Gorod
 
Cross platform mobile development using PhoneGap
Cross platform mobile development using PhoneGapCross platform mobile development using PhoneGap
Cross platform mobile development using PhoneGapKrishantha Jayathilake
 
How QCLean Works? Introduction to Browser Extensions
How QCLean Works? Introduction to Browser ExtensionsHow QCLean Works? Introduction to Browser Extensions
How QCLean Works? Introduction to Browser ExtensionsQing-Cheng Li
 
10 Golden Rules For Outstanding Titanium Apps
 10 Golden Rules For Outstanding Titanium Apps 10 Golden Rules For Outstanding Titanium Apps
10 Golden Rules For Outstanding Titanium Appsjamessugrue
 
Like a Genie from a Lamp: Headless JavaScript Unit Testing with Jasmine and P...
Like a Genie from a Lamp: Headless JavaScript Unit Testing with Jasmine and P...Like a Genie from a Lamp: Headless JavaScript Unit Testing with Jasmine and P...
Like a Genie from a Lamp: Headless JavaScript Unit Testing with Jasmine and P...Rob Friesel
 
Android1.5~8.0 Walkthrough
Android1.5~8.0 WalkthroughAndroid1.5~8.0 Walkthrough
Android1.5~8.0 WalkthroughYuki Matsumura
 
Sergey Puzankov "How to see a bug the size of 1px"
Sergey Puzankov "How to see a bug the size of 1px"Sergey Puzankov "How to see a bug the size of 1px"
Sergey Puzankov "How to see a bug the size of 1px"Fwdays
 
Typetalk APIを使ったChrome拡張開発ノウハウ #1
Typetalk APIを使ったChrome拡張開発ノウハウ #1Typetalk APIを使ったChrome拡張開発ノウハウ #1
Typetalk APIを使ったChrome拡張開発ノウハウ #1Sho Ito
 

What's hot (20)

React Nativeアプリをリリースし続けるために、最初に行う8つの取り組み
React Nativeアプリをリリースし続けるために、最初に行う8つの取り組みReact Nativeアプリをリリースし続けるために、最初に行う8つの取り組み
React Nativeアプリをリリースし続けるために、最初に行う8つの取り組み
 
Cross-platform Native App ontwikkeling met Appcelerator
Cross-platform Native App ontwikkeling met AppceleratorCross-platform Native App ontwikkeling met Appcelerator
Cross-platform Native App ontwikkeling met Appcelerator
 
Oscon 20080724
Oscon 20080724Oscon 20080724
Oscon 20080724
 
An introduction to PhantomJS: A headless browser for automation test.
An introduction to PhantomJS: A headless browser for automation test.An introduction to PhantomJS: A headless browser for automation test.
An introduction to PhantomJS: A headless browser for automation test.
 
Automatic Functional Testing with Selenium and SauceLabs
Automatic Functional Testing with Selenium and SauceLabsAutomatic Functional Testing with Selenium and SauceLabs
Automatic Functional Testing with Selenium and SauceLabs
 
Enterprise AIR Development for JavaScript Developers
Enterprise AIR Development for JavaScript DevelopersEnterprise AIR Development for JavaScript Developers
Enterprise AIR Development for JavaScript Developers
 
Banquet 42
Banquet 42Banquet 42
Banquet 42
 
探討Web ui自動化測試工具
探討Web ui自動化測試工具探討Web ui自動化測試工具
探討Web ui自動化測試工具
 
High Performance JavaScript (CapitolJS 2011)
High Performance JavaScript (CapitolJS 2011)High Performance JavaScript (CapitolJS 2011)
High Performance JavaScript (CapitolJS 2011)
 
Detecting headless browsers
Detecting headless browsersDetecting headless browsers
Detecting headless browsers
 
Webdriver.io
Webdriver.io Webdriver.io
Webdriver.io
 
lecture5
lecture5lecture5
lecture5
 
Web20expo 20080425
Web20expo 20080425Web20expo 20080425
Web20expo 20080425
 
Cross platform mobile development using PhoneGap
Cross platform mobile development using PhoneGapCross platform mobile development using PhoneGap
Cross platform mobile development using PhoneGap
 
How QCLean Works? Introduction to Browser Extensions
How QCLean Works? Introduction to Browser ExtensionsHow QCLean Works? Introduction to Browser Extensions
How QCLean Works? Introduction to Browser Extensions
 
10 Golden Rules For Outstanding Titanium Apps
 10 Golden Rules For Outstanding Titanium Apps 10 Golden Rules For Outstanding Titanium Apps
10 Golden Rules For Outstanding Titanium Apps
 
Like a Genie from a Lamp: Headless JavaScript Unit Testing with Jasmine and P...
Like a Genie from a Lamp: Headless JavaScript Unit Testing with Jasmine and P...Like a Genie from a Lamp: Headless JavaScript Unit Testing with Jasmine and P...
Like a Genie from a Lamp: Headless JavaScript Unit Testing with Jasmine and P...
 
Android1.5~8.0 Walkthrough
Android1.5~8.0 WalkthroughAndroid1.5~8.0 Walkthrough
Android1.5~8.0 Walkthrough
 
Sergey Puzankov "How to see a bug the size of 1px"
Sergey Puzankov "How to see a bug the size of 1px"Sergey Puzankov "How to see a bug the size of 1px"
Sergey Puzankov "How to see a bug the size of 1px"
 
Typetalk APIを使ったChrome拡張開発ノウハウ #1
Typetalk APIを使ったChrome拡張開発ノウハウ #1Typetalk APIを使ったChrome拡張開発ノウハウ #1
Typetalk APIを使ったChrome拡張開発ノウハウ #1
 

Similar to Build Native Apps with Alloy Using JavaScript, HTML & CSS

(Christian heilman) firefox
(Christian heilman) firefox(Christian heilman) firefox
(Christian heilman) firefoxNAVER D2
 
Firefox OS workshop, JSFoo, India
Firefox OS workshop, JSFoo, IndiaFirefox OS workshop, JSFoo, India
Firefox OS workshop, JSFoo, IndiaRobert Nyman
 
Firefox os-introduction
Firefox os-introductionFirefox os-introduction
Firefox os-introductionzsoltlengyelit
 
HTML5 vs Silverlight
HTML5 vs SilverlightHTML5 vs Silverlight
HTML5 vs SilverlightMatt Casto
 
JavaScript Misunderstood
JavaScript MisunderstoodJavaScript Misunderstood
JavaScript MisunderstoodBhavya Siddappa
 
Fixing the mobile web - Internet World Romania
Fixing the mobile web - Internet World RomaniaFixing the mobile web - Internet World Romania
Fixing the mobile web - Internet World RomaniaChristian Heilmann
 
Firefox OS - HTML5 for a truly world-wide-web
Firefox OS - HTML5 for a truly world-wide-webFirefox OS - HTML5 for a truly world-wide-web
Firefox OS - HTML5 for a truly world-wide-webChristian Heilmann
 
Attractive HTML5~開発者の視点から~
Attractive HTML5~開発者の視点から~Attractive HTML5~開発者の視点から~
Attractive HTML5~開発者の視点から~Sho Ito
 
Java Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
Java Web Programming on Google Cloud Platform [3/3] : Google Web ToolkitJava Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
Java Web Programming on Google Cloud Platform [3/3] : Google Web ToolkitIMC Institute
 
Introduction to Apache Cordova (Phonegap)
Introduction to Apache Cordova (Phonegap)Introduction to Apache Cordova (Phonegap)
Introduction to Apache Cordova (Phonegap)ejlp12
 
Introduction to Android using PhoneGap
Introduction to Android using PhoneGapIntroduction to Android using PhoneGap
Introduction to Android using PhoneGapOrisysIndia
 
Paris js extensions
Paris js extensionsParis js extensions
Paris js extensionserwanl
 
State ofappdevelopment
State ofappdevelopmentState ofappdevelopment
State ofappdevelopmentgillygize
 
vJUG - The JavaFX Ecosystem
vJUG - The JavaFX EcosystemvJUG - The JavaFX Ecosystem
vJUG - The JavaFX EcosystemAndres Almiray
 
Firefox OS - The platform you deserve - Athens App Days - 2013-11-27
Firefox OS - The platform you deserve - Athens App Days - 2013-11-27Firefox OS - The platform you deserve - Athens App Days - 2013-11-27
Firefox OS - The platform you deserve - Athens App Days - 2013-11-27Frédéric Harper
 
Mozilla Web Apps - Super-VanJS
Mozilla Web Apps - Super-VanJSMozilla Web Apps - Super-VanJS
Mozilla Web Apps - Super-VanJSRobert Nyman
 

Similar to Build Native Apps with Alloy Using JavaScript, HTML & CSS (20)

(Christian heilman) firefox
(Christian heilman) firefox(Christian heilman) firefox
(Christian heilman) firefox
 
Firefox OS workshop, JSFoo, India
Firefox OS workshop, JSFoo, IndiaFirefox OS workshop, JSFoo, India
Firefox OS workshop, JSFoo, India
 
Firefox OS
Firefox OSFirefox OS
Firefox OS
 
Firefox os-introduction
Firefox os-introductionFirefox os-introduction
Firefox os-introduction
 
HTML5 vs Silverlight
HTML5 vs SilverlightHTML5 vs Silverlight
HTML5 vs Silverlight
 
JS class slides (2016)
JS class slides (2016)JS class slides (2016)
JS class slides (2016)
 
JS Class 2016
JS Class 2016JS Class 2016
JS Class 2016
 
JavaScript Misunderstood
JavaScript MisunderstoodJavaScript Misunderstood
JavaScript Misunderstood
 
Fixing the mobile web - Internet World Romania
Fixing the mobile web - Internet World RomaniaFixing the mobile web - Internet World Romania
Fixing the mobile web - Internet World Romania
 
Firefox OS - HTML5 for a truly world-wide-web
Firefox OS - HTML5 for a truly world-wide-webFirefox OS - HTML5 for a truly world-wide-web
Firefox OS - HTML5 for a truly world-wide-web
 
Attractive HTML5~開発者の視点から~
Attractive HTML5~開発者の視点から~Attractive HTML5~開発者の視点から~
Attractive HTML5~開発者の視点から~
 
Java Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
Java Web Programming on Google Cloud Platform [3/3] : Google Web ToolkitJava Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
Java Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
 
Introduction to Apache Cordova (Phonegap)
Introduction to Apache Cordova (Phonegap)Introduction to Apache Cordova (Phonegap)
Introduction to Apache Cordova (Phonegap)
 
Introduction to Android using PhoneGap
Introduction to Android using PhoneGapIntroduction to Android using PhoneGap
Introduction to Android using PhoneGap
 
Paris js extensions
Paris js extensionsParis js extensions
Paris js extensions
 
State ofappdevelopment
State ofappdevelopmentState ofappdevelopment
State ofappdevelopment
 
vJUG - The JavaFX Ecosystem
vJUG - The JavaFX EcosystemvJUG - The JavaFX Ecosystem
vJUG - The JavaFX Ecosystem
 
Firefox OS - The platform you deserve - Athens App Days - 2013-11-27
Firefox OS - The platform you deserve - Athens App Days - 2013-11-27Firefox OS - The platform you deserve - Athens App Days - 2013-11-27
Firefox OS - The platform you deserve - Athens App Days - 2013-11-27
 
Mozilla Web Apps - Super-VanJS
Mozilla Web Apps - Super-VanJSMozilla Web Apps - Super-VanJS
Mozilla Web Apps - Super-VanJS
 
Google Web Toolkit
Google Web ToolkitGoogle Web Toolkit
Google Web Toolkit
 

More from Fokke Zandbergen

Building the (Support) Robot at Zapier
Building the (Support) Robot at ZapierBuilding the (Support) Robot at Zapier
Building the (Support) Robot at ZapierFokke Zandbergen
 
Lessons from helping developers integrate 1,000 APIs with Zapier
Lessons from helping developers integrate 1,000 APIs with ZapierLessons from helping developers integrate 1,000 APIs with Zapier
Lessons from helping developers integrate 1,000 APIs with ZapierFokke Zandbergen
 
We are all Remote Advocates
We are all Remote AdvocatesWe are all Remote Advocates
We are all Remote AdvocatesFokke Zandbergen
 
Cross-Platform Native Apps with JavaScript
Cross-Platform Native Apps with JavaScriptCross-Platform Native Apps with JavaScript
Cross-Platform Native Apps with JavaScriptFokke Zandbergen
 
Titanium: Develop Native Mobile Apps with JavaScript
Titanium: Develop Native Mobile Apps with JavaScriptTitanium: Develop Native Mobile Apps with JavaScript
Titanium: Develop Native Mobile Apps with JavaScriptFokke Zandbergen
 
Appcelerator OSS & Platform
Appcelerator OSS & PlatformAppcelerator OSS & Platform
Appcelerator OSS & PlatformFokke Zandbergen
 
Platform 4.0 Meetup Launch Event
Platform 4.0 Meetup Launch EventPlatform 4.0 Meetup Launch Event
Platform 4.0 Meetup Launch EventFokke Zandbergen
 
The Ultimate Titanium CLI Toolchain
The Ultimate Titanium CLI ToolchainThe Ultimate Titanium CLI Toolchain
The Ultimate Titanium CLI ToolchainFokke Zandbergen
 
Getting ready for iOS 8 & iPhone 6
Getting ready for iOS 8 & iPhone 6Getting ready for iOS 8 & iPhone 6
Getting ready for iOS 8 & iPhone 6Fokke Zandbergen
 
Titanium Community Toolkit Showcase
Titanium Community Toolkit ShowcaseTitanium Community Toolkit Showcase
Titanium Community Toolkit ShowcaseFokke Zandbergen
 
5 app alternatieven #AIB2013
5 app alternatieven #AIB20135 app alternatieven #AIB2013
5 app alternatieven #AIB2013Fokke Zandbergen
 
Apps voor kerken #Kerk2013
Apps voor kerken #Kerk2013Apps voor kerken #Kerk2013
Apps voor kerken #Kerk2013Fokke Zandbergen
 
Alloy Tips & Tricks #TiLon
Alloy Tips & Tricks #TiLonAlloy Tips & Tricks #TiLon
Alloy Tips & Tricks #TiLonFokke Zandbergen
 

More from Fokke Zandbergen (20)

Building the (Support) Robot at Zapier
Building the (Support) Robot at ZapierBuilding the (Support) Robot at Zapier
Building the (Support) Robot at Zapier
 
Lessons from helping developers integrate 1,000 APIs with Zapier
Lessons from helping developers integrate 1,000 APIs with ZapierLessons from helping developers integrate 1,000 APIs with Zapier
Lessons from helping developers integrate 1,000 APIs with Zapier
 
We are all Remote Advocates
We are all Remote AdvocatesWe are all Remote Advocates
We are all Remote Advocates
 
Cross-Platform Native Apps with JavaScript
Cross-Platform Native Apps with JavaScriptCross-Platform Native Apps with JavaScript
Cross-Platform Native Apps with JavaScript
 
Titanium: Develop Native Mobile Apps with JavaScript
Titanium: Develop Native Mobile Apps with JavaScriptTitanium: Develop Native Mobile Apps with JavaScript
Titanium: Develop Native Mobile Apps with JavaScript
 
Appcelerator OSS & Platform
Appcelerator OSS & PlatformAppcelerator OSS & Platform
Appcelerator OSS & Platform
 
Platform 4.0 Meetup Launch Event
Platform 4.0 Meetup Launch EventPlatform 4.0 Meetup Launch Event
Platform 4.0 Meetup Launch Event
 
The Ultimate Titanium CLI Toolchain
The Ultimate Titanium CLI ToolchainThe Ultimate Titanium CLI Toolchain
The Ultimate Titanium CLI Toolchain
 
Getting ready for iOS 8 & iPhone 6
Getting ready for iOS 8 & iPhone 6Getting ready for iOS 8 & iPhone 6
Getting ready for iOS 8 & iPhone 6
 
Titanium Community Toolkit Showcase
Titanium Community Toolkit ShowcaseTitanium Community Toolkit Showcase
Titanium Community Toolkit Showcase
 
Titanium Alloy Tutorial
Titanium Alloy TutorialTitanium Alloy Tutorial
Titanium Alloy Tutorial
 
5 app alternatieven #AIB2013
5 app alternatieven #AIB20135 app alternatieven #AIB2013
5 app alternatieven #AIB2013
 
Apps voor kerken #Kerk2013
Apps voor kerken #Kerk2013Apps voor kerken #Kerk2013
Apps voor kerken #Kerk2013
 
TiNy #TiAppCamp
TiNy #TiAppCampTiNy #TiAppCamp
TiNy #TiAppCamp
 
Internetmarketing
InternetmarketingInternetmarketing
Internetmarketing
 
Alloy Tips & Tricks #TiLon
Alloy Tips & Tricks #TiLonAlloy Tips & Tricks #TiLon
Alloy Tips & Tricks #TiLon
 
Alloy #DMC13
Alloy #DMC13Alloy #DMC13
Alloy #DMC13
 
Titanium #MDS13
Titanium #MDS13Titanium #MDS13
Titanium #MDS13
 
SEO
SEOSEO
SEO
 
Alloy
AlloyAlloy
Alloy
 

Build Native Apps with Alloy Using JavaScript, HTML & CSS

  • 1. Appcelerator Alloy MVC tiConf Dhaka, Bangladesh Feb 10th, 2015 Fokke Zandbergen @FokkeZB
  • 2. Show your hand if you know a programming language ✌
  • 3. Show your hand if you've used HTML & CSS ✌
  • 4. Show your hand if you’ve used JavaScript ✌
  • 5. Show your hand if you’ve used Titanium ✌
  • 6. Classic app.js var window = Ti.UI.createWindow({ backgroundColor: “white" }); var label = Ti.UI.createLabel({ text: “Hello World” }); label.addEventListener(“click”, function open() { alert(“Hello World”); } ); window.add(label); window.open(); style logic markup logic markupmarkup
  • 8. Alloy <Alloy> <Window> <Label onClick=”open”>Hello World</Label> </Window> </Alloy> ”Window”: { backgroundColor: “white” } function open() { alert(“Hello World”); } $.index.open(); index.xml index.tss index.js
  • 9. Familiar • HTML-like XML • CSS-like TSS • JavaScript • No HTML UI • No overhead • Compiles to Classic …but better
  • 10. Compiled simplified module.exports = function Controller() { var $ = this; $.index = Ti.UI.createWindow({ backgroundColor: “white” }); $.__alloyId1 = Ti.UI.createLabel({ text: “Hello World” }); $.__alloyId1.addEventListener(“click”, open); $.index.add($.__alloyId1); function open() { alert(“Hello World”); } $.index.open(); }; index.tss index.xml index.js
  • 11. Structure simplified ▾ app ▾ assets ▾ images
 logo.png ▾ controllers index.js ▾ lib utils.js ▾ styles index.tss ▾ views index.xml ▾ widgets alloy.js config.json tiapp.xml ▸ app ▾ Resources ▾ alloy ▾ controllers index.js backbone.js CFG.js underscore.js ▾ images logo.png alloy.js app.js utils.js tiapp.xml ▾ Resources ▾ images logo.png app.js main.js utils.js tiapp.xml
  • 13. Classes, ids and tags <Alloy> <Window> <Label id=”lbl” class=”red big”>Hello</Label> </Window> </Alloy> index.xml ”Window”: { backgroundColor: “white” } ”#lbl”: { backgroundColor: “green” } ”.red”: { color: “red” } ”.big”: { font: { fontSize: 20 } ”.bold”: { font: { fontWeight: ”bold” } $.index.open(); $.lbl.text = “bye”; $.addClass($.lbl, “bold”); index.tss index.js
  • 14. Conditional code <Alloy> <Label platform=”ios,!android”>iOS, Windows</Label> <Label formFactor=”handheld”>Handheld</Label> <Label if=”Alloy.Globals.iOS8”>iOS 8</Label> </Alloy> ”Label[platform=ios,!android formFactor=tablet]”: { color: “red” } ”Label[if=Alloy.Globals.iOS8]”: { backgroundColor: “green” } if (OS_IOS && ENV_PRODUCTION && DIST_STORE) { alert(“iOS App Store, not Ad Hoc”); } index.xml index.tss index.js
  • 15. if (OS_IOS && ENV_TEST && Alloy.CFG.foo !== 7) { alert(“Wrong!”); } Conditional config { "global": {"foo":1}, "env:development": {"foo":2}, "env:test":{"foo":3}, "env:production":{"foo":4}, "os:ios env:production": {"foo":5}, "os:ios env:development": {"foo":6}, "os:ios env:test": {"foo":7}, "os:android":{"foo":8}, "os:mobileweb":{"foo":9}, "dependencies": { “com.foo.widget":"1.0" } } config.json > CFG.js index.js
  • 16. Global namespace var uuid = Ti.Platform.createUUID(); // wrong (function(global) { var version = Ti.Platform.version; // safe Alloy.Globals.iOS8 = version.split(“.”)[0] === ”8”; global.started = Ti.Platform.createUUID(); // avoid Alloy.Globals.seed = Ti.Platform.createUUID(); // better })(this); alloy.js > app.js module.exports = { seed: Ti.Platform.createUUID(); // best }; utils.js
  • 17. Data binding <Alloy> <Collection src=”album” /> <TableView dataCollection=”album” dataTransform=”transformer” dataFilter=”filter”> <TableViewRow title=”{title} by {artist}” /> </TableView> </Alloy> index.xml function filter(collection) { return collection.where({artist:”Beatles”}); } function transformer(model) { var tf = model.toJSON(); tf.title = tf.title.toUpperCase(); return tf; } index.js
  • 18. Themes • Set in config.json • Overwrites assets • Merges styles • Merges config ▾ app ▾ assets ▾ images
 logo.png ▸ controllers ▾ styles index.tss ▸ views ▾ themes ▾ green ▾ assets logo.png ▾ styles index.tss config.json config.json whitelabelapps
  • 19. Widgets ▾ app ▸ assets ▸ lib ▸ controllers ▸ styles ▸ views ▾ widgets ▸ mine ▸ assets ▸ lib ▾ controllers widget.tss ▸ styles ▸ views widget.json config.json <Alloy> <Require src=”foo” /> <Widget src=”mine” /> <Widget src=”mine” name=”bar” /> </Alloy> • apps in apps • 400+ open source • theme-able!
  • 21. Alloy 1.6.0 (Q1) • Support for Windows Phone • Support for promises in sync adapters • Upgrade Backbone 0.9.2 > 1.1.2 • Upgrade Underscore 1.4.4 > 1.6.0 • Support for two-way-data-binding via Nano • More than 25 other fixes/improvements
  • 22. © Saint Bernadine Mission Communications Inc. Q
  • 23. If you know JS, HTML & CSS You can build native apps with Alloy