[143]inside fuse deview 2016

32
Anders Lassen CEO, Fuse Inside Fuse: Achieving full native UI performance with JavaScript

Upload: naver-d2

Post on 07-Jan-2017

636 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: [143]Inside fuse   deview 2016

Anders LassenCEO, Fuse

Inside Fuse:Achieving full native UI performance with JavaScript

Page 2: [143]Inside fuse   deview 2016

1.Intro to Fuse2.Asynchronous JavaScript Architecture3.Fuse+Angular2

Agenda

Page 3: [143]Inside fuse   deview 2016

1.Intro to Fuse

Page 4: [143]Inside fuse   deview 2016

Native mobile app development platform / engine

Super fast native UI, animation & effects

Animation & UI in easy XML

Business logic in plain JavaScript

Optional: Use any JS framework on top (e.g. Angular 2)

What is Fuse?

Page 5: [143]Inside fuse   deview 2016

Live coding time!

Page 6: [143]Inside fuse   deview 2016

Built with Fuse

(Soon)

Page 7: [143]Inside fuse   deview 2016

Built with Fuse

Page 8: [143]Inside fuse   deview 2016

Try it out atfusetools.com

Page 9: [143]Inside fuse   deview 2016

2.Fuse’s Asynchronous JavaScript Architecture

Page 10: [143]Inside fuse   deview 2016

How can we use JavaScript to build mobile apps without risking UI performance issues?

Page 11: [143]Inside fuse   deview 2016

Mobile JS platforms have always had performance problems.Why?Because: Any JS operation will block the UI thread.

- HTML5/Cordova = slow, not native UX

- Native UI + JS = JS still single-threaded!

JS in mobile

Page 12: [143]Inside fuse   deview 2016

Single-threaded JS platforms

Main ThreadNative CodeRender UI

JS compute animation

JS business logic & data preparation

JS compute layout

Never slower than 60 times per second?

Page 13: [143]Inside fuse   deview 2016

• Run all JavaScript logic on a background thread.

• Render UI on main thread using native components.

• Minimal and precise UI updates.

• No expensive diffing or change detection on UI thread.

Fuse Design Goals

Page 14: [143]Inside fuse   deview 2016

Core idea: Two threads

Main Thread

Native CodeRender UI

Native Code Layout & Animation

JS Thread

JS business logic & data preparation

Native APIs

But how do we communicate between UI and JS ?

Page 15: [143]Inside fuse   deview 2016

Observables• In Fuse, all communication between JS and UI happens

through Observables.

• Observable() holds one or more values that can change.

• Observable emits messages when the data changes.

Page 16: [143]Inside fuse   deview 2016

How Observables workvar apples = Observable(10);

var message = Observable(function() {

return “I have “ + apples.value + “ apples.”;

});

function add_apple() {

apples.value = apples.value + 1;

}

I have 10 apples.Add one more

Page 17: [143]Inside fuse   deview 2016

var apples = Observable(10);

var message = Observable(function() {

return “I have “ + apples.value + “ apples.”;

});

function add_apple() {

apples.value = apples.value + 1;

}

Observable Dataflow

I have 10 apples.Add one more

UI update queue

Tapped!

11“I have 11 apples”

UI ThreadJS Thread

JS Event queue

11 I have 11 apples.

11

Page 18: [143]Inside fuse   deview 2016

Observables are also listsvar things = Observable(“car”, “hat”, “apple”);

add(“lemon”)

“lemon”);

things.add(“lemon”);

Precise manipulation of UIMinimal layout changesAnimated response

things.remove(“hat”);remove(“hat”)

Page 19: [143]Inside fuse   deview 2016

Observables are also listsvar things = Observable(“car”, “hat”, “apple”); “lemon”);

things.add(“lemon”);…

things.remove(“hat”);

add(“lemon”)

Precise manipulation of UIMinimal layout changesAnimated response

remove(“hat”)

Page 20: [143]Inside fuse   deview 2016

Reactive Operators (.map)var numbers = Observable(4, 5, 7);

var foo = numbers.map(function(c) {

return c*2;

});

[1] = 13

[1] = 26 8 10 14Lucky numbers

Precise update of only affected cell

numbers.replaceAt(1, 13);

26

13

Page 21: [143]Inside fuse   deview 2016

Async Reactive Queries var movies = Observable();

var moviesWithBatman = movies.where(function(m) {

return m.title.indexOf(“Batman”) != -1;

});

fetchMovies().then(function(result) {

movies.replaceAll(result);

});

Page 22: [143]Inside fuse   deview 2016

Async Reactive Queries var movies = Observable();

var moviesWithBatman = movies.where(function(m) {

return m.title.indexOf(“Batman”) != -1;

});

fetchMovies().then(function(result) {

movies.replaceAll(result);

});

Page 23: [143]Inside fuse   deview 2016

Benefits of JS Observables• UI can be updated completely asynchronously with precise,

minimal UI invalidation.

• Allows async reactive operators (e.g. map() and where())

• No change detection required (as in Angular)

• No component re-render & diffing required (as in React)

Page 24: [143]Inside fuse   deview 2016

The Fuse Architecture

Main Thread

Native CodeRender UI

Native Code Layout & Animation

JS Thread

JS business logic & data preparation

User input events

Observabledata changes

Native APIs

Page 25: [143]Inside fuse   deview 2016

Benefits of Async JavaScriptThe UI performance is never affected by what you do in JavaScript.

• Processing/preparing large datasets• Calling into native APIs• Processing images

• And ultimately: Eliminates all overhead from using any JavaScript framework, such as Angular 2

Page 26: [143]Inside fuse   deview 2016

3.Fuse+Angular 2

Page 27: [143]Inside fuse   deview 2016

Fuse + Angular 2Frameworks such as Angular 2 are optional in Fuse.

Benefits of using Angular 2:• Adds structure to larger JS projects.• Share code between native app and web.• Lots of utilities, helpers, docs, infrastructure, community.

Angular 2 is heavy - but thanks to Fuse’s async architectureyour UI performance is safe. Let’s see how!

Page 28: [143]Inside fuse   deview 2016

How to use Fuse + Angular 2.ngux - Define Angular 2 templates in Fuse UX Markup

.ts - Shared JS business logic between .ngux and .html

Page 29: [143]Inside fuse   deview 2016

Let’s see Fuse+Angular2!

Page 30: [143]Inside fuse   deview 2016

Fuse+Async Angular2

Angular 2 Change Detector

Angular 2 Component Tree

Virtual DOMChanges

Angular 2 RendererInterface

Custom FuseImplementation

“Virtual DOM” =Simplified tree of Observables

Data Changes

JS ThreadUI Thread

Plain Data Changes

Page 31: [143]Inside fuse   deview 2016

Q&A

Page 32: [143]Inside fuse   deview 2016

Thank You