xamarin - microsoft · assumptions and expectations knowledge of building apps with xamarin...

26
XAMARIN.FLUX Architecting in Xamarin Alex Dunn Blog: https://alexdunn.org GitHub: @SuavePirate Twitter: @Suave_Pirate

Upload: vuongthu

Post on 17-Apr-2018

233 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Xamarin - Microsoft · ASSUMPTIONS AND EXPECTATIONS Knowledge of building apps with Xamarin Familiarity with Xamarin.Forms Familiarity with XAML Familiarity with …

XAMARIN.FLUXArchitectinginXamarin

AlexDunnBlog:https://alexdunn.orgGitHub:@SuavePirateTwitter:@Suave_Pirate

Page 2: Xamarin - Microsoft · ASSUMPTIONS AND EXPECTATIONS Knowledge of building apps with Xamarin Familiarity with Xamarin.Forms Familiarity with XAML Familiarity with …

TOPICS▪ WhatisFlux?

▪ WhyuseFlux?

▪ AlookataFluximplementationinC#

▪ Buildinganappfromscratch

Page 3: Xamarin - Microsoft · ASSUMPTIONS AND EXPECTATIONS Knowledge of building apps with Xamarin Familiarity with Xamarin.Forms Familiarity with XAML Familiarity with …

ASSUMPTIONSANDEXPECTATIONS▪ KnowledgeofbuildingappswithXamarin

▪ FamiliaritywithXamarin.Forms

▪ FamiliaritywithXAML

▪ FamiliaritywithMVVMandBindings

Page 4: Xamarin - Microsoft · ASSUMPTIONS AND EXPECTATIONS Knowledge of building apps with Xamarin Familiarity with Xamarin.Forms Familiarity with XAML Familiarity with …

RESOURCES▪ InitialProject:https://github.com/SuavePirate/XamU

▪ CompleteProject:https://github.com/SuavePirate/Xamarin.Flux

▪ Video:https://www.youtube.com/watch?v=CJh1kRXK2qI&t=1303s

▪ FluxDocs:https://facebook.github.io/flux/docs/overview.html#content

▪ FluxDemosandExamples:https://github.com/facebook/flux

Page 5: Xamarin - Microsoft · ASSUMPTIONS AND EXPECTATIONS Knowledge of building apps with Xamarin Familiarity with Xamarin.Forms Familiarity with XAML Familiarity with …

WHATISFLUX?

Page 6: Xamarin - Microsoft · ASSUMPTIONS AND EXPECTATIONS Knowledge of building apps with Xamarin Familiarity with Xamarin.Forms Familiarity with XAML Familiarity with …

OVERVIEW▪ Client-sideApplicationArchitecture/DesignPattern

▪ DesignedbyFacebook

▪ Usedforbuildingrobustdata-drivenUserInterfaces

▪ Focusonflowofdataandseparationofconcerns

▪ Unidirectionaldataflows

▪ BuiltforReact.js

Page 7: Xamarin - Microsoft · ASSUMPTIONS AND EXPECTATIONS Knowledge of building apps with Xamarin Familiarity with Xamarin.Forms Familiarity with XAML Familiarity with …

FROMREACT.JS TOC#+XAMARINReact.js

▪ ComponentRender

▪ ComponentState

▪ ComponentProps

▪ ComponentLifecycle

C#+Xamarin +MVVM

▪ XAML/C#Page/View

▪ ViewModel

▪ ViewProperties

▪ PageLifecycleandtwowaybinding

Page 8: Xamarin - Microsoft · ASSUMPTIONS AND EXPECTATIONS Knowledge of building apps with Xamarin Familiarity with Xamarin.Forms Familiarity with XAML Familiarity with …

BASICSTRUCTURE▪ Actions

▪ Dispatcher

▪ Stores

▪ Views

Viewtakesupdateddata

fromstoreandupdatesUI

View

Takesmessagefrom

dispatcherandupdatesdata.Emitschanges

downtoobserving

views

Store

Dispatchertakesdata

fromactionand

dispatchesittosubscribed

stores

DispatcherAnactiondoessomebusiness

logicandcommunicates

datatothedispatcher

Action

Page 9: Xamarin - Microsoft · ASSUMPTIONS AND EXPECTATIONS Knowledge of building apps with Xamarin Familiarity with Xamarin.Forms Familiarity with XAML Familiarity with …

ADVANCEDSTRUCTURE▪ Actions

▪ Dispatcher

▪ Stores

▪ Views

▪ Actions

▪ Dispatcher

▪ Stores

▪ ….repeat

Repeatprocess

Action

Viewtakesupdateddata

fromstoreandupdates

UIViewfiresanotheraction

View

Takesmessagefrom

dispatcherandupdatesdata.Emits

changesdowntoobserving

views

Store

Dispatchertakesdata

fromactionand

dispatchesittosubscribed

stores

DispatcherAnaction

doessomebusinesslogic

andcommunicates

datatothedispatcher

Action

Page 10: Xamarin - Microsoft · ASSUMPTIONS AND EXPECTATIONS Knowledge of building apps with Xamarin Familiarity with Xamarin.Forms Familiarity with XAML Familiarity with …

STRUCTUREADJUSTEDFORXAMARINANDMVVM▪ Actions

▪ Dispatcher

▪ Stores

▪ ViewModels

▪ Views

▪ ViewModels

▪ Actions

▪ ….repeat

Repeatprocess

Action

ViewModelfiresanaction

fromtheboundcommand

ViewModel

ViewautomaticallyupdatesfrombindingstoViewModelViewfires

anotheractiontothe

ViewModelthrougha

boundCommand

View

ViewModeltakesupdated

datafromstoreandupdates

bindableproperties

ViewModel

Takesmessagefromdispatcher

andupdatesdata.Emits

changesdowntoobserving

views

Store

Dispatchertakesdatafrom

actionanddispatchesitto

subscribedstores

DispatcherAnactiondoes

somesmallbusinesslogic

andcommunicates

datatothedispatcher

Action

Page 11: Xamarin - Microsoft · ASSUMPTIONS AND EXPECTATIONS Knowledge of building apps with Xamarin Familiarity with Xamarin.Forms Familiarity with XAML Familiarity with …

WHYUSEFLUX?

Page 12: Xamarin - Microsoft · ASSUMPTIONS AND EXPECTATIONS Knowledge of building apps with Xamarin Familiarity with Xamarin.Forms Familiarity with XAML Familiarity with …

PROBLEMSWITHPASTPATTERNS▪ Bidirectionaldesign,suchasMVC

▪ Allowedformultiplecontrollerstotalktoeachother

▪ Datapassedbetweencontrollersfrequently

▪ Hardtomaintainatanextremelylargescale

▪ Changesthattrickledowntomultiplecontrollersorviewsarehardtotrackandtest

▪ Generaldataflowisnotwelldefined

▪ Looserulesofdataflowcausedrasticallydifferentimplementations(seeCocoaMVCvsASP.NETMVCvs.RubyonRailsMVC)

Page 13: Xamarin - Microsoft · ASSUMPTIONS AND EXPECTATIONS Knowledge of building apps with Xamarin Familiarity with Xamarin.Forms Familiarity with XAML Familiarity with …

SOLUTIONSFROMFLUX▪ DataFlow

▪ Dataflowsinasingledirection

▪ Trickledowncontrol▪ Allowsforviewstolistentochangesinmultiplestores▪ Allowsformultiplestorestolistentothesamedispatchedevents▪ Allowsformultipleviewstoinvokethesameaction

▪ Datahasasinglepoint– Stores▪ Dataofasingledomain/areacanbeaccessedbyanynumberofviews

▪ CanstilllivealongsideotherpatternssuchasMVVMbinding

▪ Playswellwithotherprojectarchitecturesandpatternssuchas▪ DDD▪ Onion▪ IoC/DI

Page 14: Xamarin - Microsoft · ASSUMPTIONS AND EXPECTATIONS Knowledge of building apps with Xamarin Familiarity with Xamarin.Forms Familiarity with XAML Familiarity with …

COMPLEXDATAFLOWS

ViewsStoresActions

Action1Store1

View1

View2

Store2 View3

Page 15: Xamarin - Microsoft · ASSUMPTIONS AND EXPECTATIONS Knowledge of building apps with Xamarin Familiarity with Xamarin.Forms Familiarity with XAML Familiarity with …

COMPLEXDATAFLOWS

ViewsStoresActionsViews

View1Action1

Store1View2

View1Store2

Action2

Page 16: Xamarin - Microsoft · ASSUMPTIONS AND EXPECTATIONS Knowledge of building apps with Xamarin Familiarity with Xamarin.Forms Familiarity with XAML Familiarity with …

XAMARIN.FORMS:FLUX+MVVM+IOC/DISourceCode:https://github.com/SuavePirate/Xamarin.Flux

Page 17: Xamarin - Microsoft · ASSUMPTIONS AND EXPECTATIONS Knowledge of building apps with Xamarin Familiarity with Xamarin.Forms Familiarity with XAML Familiarity with …

PROJECTSTRUCTUREXamarin.Forms XAMLPCLTemplate

Page 18: Xamarin - Microsoft · ASSUMPTIONS AND EXPECTATIONS Knowledge of building apps with Xamarin Familiarity with Xamarin.Forms Familiarity with XAML Familiarity with …

PROJECTSTRUCTURE• FluxSpecificComponents

• TodoActions.cs

• TodoActionTypes.cs (eventidentifiers)

• TodoStore.cs

• Dispatcher(usingMessagingCenter fromXamarin.Forms)

• MVVMSpecificComponents• TodoListPageViewModel.cs

• TodoListPage.xaml

• IoC/DISpecificComponents• IoCConfig.cs

• ViewModelLocator.cs

• OtherfilesaremostlyforkeepingacleancodebaseandmaintainingbestC#practices

Page 19: Xamarin - Microsoft · ASSUMPTIONS AND EXPECTATIONS Knowledge of building apps with Xamarin Familiarity with Xamarin.Forms Familiarity with XAML Familiarity with …

RUNNINGTHEAPP– CREATEITEM

Page 20: Xamarin - Microsoft · ASSUMPTIONS AND EXPECTATIONS Knowledge of building apps with Xamarin Familiarity with Xamarin.Forms Familiarity with XAML Familiarity with …

RUNNINGTHEAPP– VIEWINGITEM

Page 21: Xamarin - Microsoft · ASSUMPTIONS AND EXPECTATIONS Knowledge of building apps with Xamarin Familiarity with Xamarin.Forms Familiarity with XAML Familiarity with …

RUNNINGTHEAPP– UPDATINGANITEM

Page 22: Xamarin - Microsoft · ASSUMPTIONS AND EXPECTATIONS Knowledge of building apps with Xamarin Familiarity with Xamarin.Forms Familiarity with XAML Familiarity with …

RUNNINGTHEAPP– VIEWINGDATA

Page 23: Xamarin - Microsoft · ASSUMPTIONS AND EXPECTATIONS Knowledge of building apps with Xamarin Familiarity with Xamarin.Forms Familiarity with XAML Familiarity with …

RUNNINGTHEAPP– DELETINGANITEM

Page 24: Xamarin - Microsoft · ASSUMPTIONS AND EXPECTATIONS Knowledge of building apps with Xamarin Familiarity with Xamarin.Forms Familiarity with XAML Familiarity with …

RUNNINGTHEAPP– DELETINGALLCOMPLETEDITEMS

Page 25: Xamarin - Microsoft · ASSUMPTIONS AND EXPECTATIONS Knowledge of building apps with Xamarin Familiarity with Xamarin.Forms Familiarity with XAML Familiarity with …

RUNNINGTHEAPP– TOGGLINGALLITEMS

Page 26: Xamarin - Microsoft · ASSUMPTIONS AND EXPECTATIONS Knowledge of building apps with Xamarin Familiarity with Xamarin.Forms Familiarity with XAML Familiarity with …

BUILDITFROMSCRATCHLet’swritesomecode.