building single page apps with durandal js

26
Building Single Page Apps with DurandalJS @kennethtruyers www.kenneth-truyers.net

Upload: alex-andreu-sanchez

Post on 19-Jun-2015

749 views

Category:

Technology


4 download

TRANSCRIPT

Page 1: Building single page apps with Durandal js

Building Single Page Apps with DurandalJS

@kennethtruyers

www.kenneth-truyers.net

Page 2: Building single page apps with Durandal js

What is a Single Page App?

Web app that fits on a single page. It provides fluent UX by loading all necessary data on page load and

then fetch progressively

Page 3: Building single page apps with Durandal js

Why should I build a SPA?

• Reach

• Devices, platforms, browsers

• Rich user experience

• Fluent pages through client-side navigation

• Reduced round tripping

Page 4: Building single page apps with Durandal js

Common traits

• Deep client-side linking

• Load what’s needed on page-load

• Progressively download when required

• Easy state maintenance

Page 5: Building single page apps with Durandal js

Demo: application overview

Page 6: Building single page apps with Durandal js

Presenting DurandalJS

AMD (Module loading)

Data binding

DOM manipulation

UI (optional)

Page 7: Building single page apps with Durandal js

Architecture

Client Server

REST

CSS

RequireJS

Knockout

jQueryBootstra

p

Views (HTML)ViewModels (JS)

Durandal

Page 8: Building single page apps with Durandal js

Demo: application code

Page 9: Building single page apps with Durandal js

Key concepts

• Modularization

• Routing

• Binding

• Composition

• Lifecycle & Promises

Page 10: Building single page apps with Durandal js

Modularization with RequireJS define(['jquery', 'knockout'], function ($, ko) {

var loaddata = function() { $.ajax( ...); }; var name = "myname";

return { activate: loaddata, name: name }; });

AMD wrap

Dependencies

Private

Public interface

Page 11: Building single page apps with Durandal js

Demo: Modularization

Page 12: Building single page apps with Durandal js

Routing

• Client-side routing

• Deep linking

• URL parameters

• Route configuration

Page 13: Building single page apps with Durandal js

Demo: routing

Page 14: Building single page apps with Durandal js

Binding with Knockout

• Three binding types

• Simple properties

• ObservableArrays

• Computed

Page 15: Building single page apps with Durandal js

Demo: binding

Page 16: Building single page apps with Durandal js

Composition

• Object composition

• RequireJS and Module loading

• Visual composition

• Durandal feature

• Compose views + viewmodels inside other views

Page 17: Building single page apps with Durandal js

Demo: Composition

Page 18: Building single page apps with Durandal js

Lifecycle & promises

• Every page has “hooks” we can use to control behavior

• Lifecycle:

• Deactivation

• Activation

• Binding

• Composition

Page 19: Building single page apps with Durandal js

Lifecycle & promises

• Deactivation

• canDeactivate()

• deactivate()

• Activation

• canActivate()

• activate()

• Binding

• binding()

• bindingComplete()

• Composition

• attached()

• compositionComplete()

• detached()

Page 20: Building single page apps with Durandal js

Demo: Lifecycle & promises

Page 21: Building single page apps with Durandal js

Durandal: overview

• Modularization

• Routing

• Binding

• Composition

• Lifecycle & Promises

Page 22: Building single page apps with Durandal js

The future of Durandal

• Durandal + Angular Merge into Angular 2.0

• Bringing strong suits of each framework together

Page 23: Building single page apps with Durandal js

Durandal + Angular merge

• Durandal

• Standardized module system

• Lifecycle & promises

• Composition

• Angular

• Web components through (improved) directives

• Databinding

• Routing

• ES6 + modern browser

• Non backward-compatible

Page 24: Building single page apps with Durandal js

How to get it?• Nuget

• Install-Package durandal• Bower

• bower install durandal• Mimosa

• mimosa skel:new durandal• Raw downloads:

• durandaljs.com

• github.com/bluespire/durandal

• Visual Studio gallery: visualstudiogallery.msdn.microsoft.com

Page 25: Building single page apps with Durandal js

Links

• Demo application

• github.com/Kennethtruyers/DurandalDemos

• Docs & downloads

• durandaljs.com

• GitHub

• github.com/BlueSpire/Durandal

• Support

• Stackoverflow

• groups.google.com/forum/#!forum/durandaljs

Page 26: Building single page apps with Durandal js

Q & A